Go Down

Topic: debug HELP!!!!!!! (Read 436 times) previous topic - next topic

ittsuck

i need help with this code for school im stuck on this part and i tried many different thing to do but i cant figure it out. its the same code that keeps coming iup error: stray '\' in program In function 'void loop()':
In function 'void shiftOut(int, int, byte)':


heres the code i need to debug

// by rob natebu.wordpress.com

int dataPin = 10; //DS
int latchPin = 9; //ST
int clockPin = 8; //SH

int sS0 = 7; //sS0
int sS1 = 6; //sS1
int sS2 = 5; //sS2

int mS0 = 4; //mS0
int mS1 = 3; //mS1
int mS2 = 2; //mS2

// Pinf for the Status LED
int led = 13;

// Pin for the IR LEDs
int LEDpin = 11;

// Analog Inputs von den Fototransistoren
int analogInput = 0;

// variable to store the value

int values0[] = {
0, 0, 0, 0, 0, 0, 0, 0};
int values1[] = {
0, 0, 0, 0, 0, 0, 0, 0};
int values2[] = {
0, 0, 0, 0, 0, 0, 0, 0};
int values3[] = {
0, 0, 0, 0, 0, 0, 0, 0};
int values4[] = {
0, 0, 0, 0, 0, 0, 0, 0};
int values5[] = {
0, 0, 0, 0, 0, 0, 0, 0};
int values6[] = {
0, 0, 0, 0, 0, 0, 0, 0};
int values7[] = {
0, 0, 0, 0, 0, 0, 0, 0};

int values[8][8]; //display
int counters[8][8];//storrage

// a threshold to decide when the LED turns on 512 normal
int threshold = 700;

int timer = 0;

//holders for infromation you're going to pass to shifting function
byte dataRED;
byte dataGREEN;
byte dataArrayRED[8];
byte dataArrayGREEN[8];

//alles für den multiplexer
int rm0 = 0; // value Master 4051 (s0)
int rm1 = 0; // value Master 4051 (s1)
int rm2 = 0; // value Master 4051 (s2)
int rowM = 0; // storeing the bin code
int bin [] = {
000, 1, 10, 11, 100, 101, 110, 111};//bin = binär, some times it is so easy

int rs0 = 0; // value Slave 4051 (s0)
int rs1 = 0; // value Slave 4051 (s1)
int rs2 = 0; // value Slave 4051 (s2)
int rowS = 0; // storeing the bin code

void setup() {

//multiplexer
pinMode(mS0, OUTPUT); // Master s0
pinMode(mS1, OUTPUT); // Master s1
pinMode(mS2, OUTPUT); // Master s2

pinMode(sS0, OUTPUT); // Slave s0
pinMode(sS1, OUTPUT); // Slave s1
pinMode(sS2, OUTPUT); // Slave s2

digitalWrite(led, HIGH); //die kontroll LED

//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);

//set the pin for the IR LEDs
pinMode(LEDpin, OUTPUT);
digitalWrite(LEDpin, HIGH);

// Analog Inputs von den Fototransistoren
pinMode(analogInput, INPUT);

dataArrayGREEN[0] = 254;
dataArrayGREEN[1] = 253;
dataArrayGREEN[2] = 251;
dataArrayGREEN[3] = 247;
dataArrayGREEN[4] = 239;
dataArrayGREEN[5] = 223;
dataArrayGREEN[6] = 191;
dataArrayGREEN[7] = 127;

for(int j = 0; j < 8; j++){
values[0][j] = values0[j];
values[1][j] = values1[j];
values[2][j] = values2[j];
values[3][j] = values3[j];
values[4][j] = values4[j];
values[5][j] = values5[j];
values[6][j] = values6[j];
values[7][j] = values7[j];
}
for(int i = 0; i < 8; i++){
for(int j = 0; j < 8; j++){
counters[j] = 0;
}
}
}

void loop() {

/// Multiplexer read alle
for (int countM=0; countM<8; countM++) {
rowM = bin[countM];
rm0 = rowM & 0×01;
rm1 = (rowM>>1) & 0×01;
rm2 = (rowM>>2) & 0×01;
digitalWrite(mS0, rm0);
digitalWrite(mS1, rm1);
digitalWrite(mS2, rm2);

for (int countS=0; countS<8; countS++) {
rowS = bin[countS];
rs0 = rowS & 0×01;
rs1 = (rowS>>1) & 0×01;
rs2 = (rowS>>2) & 0×01;
digitalWrite(sS0, rs0);
digitalWrite(sS1, rs1);
digitalWrite(sS2, rs2);

if(values[countS][countM] == 1) {
counters[countS][countM] = counters[countS][countM] + 1;
}
if( counters[countS][countM] > 50) {
counters[countS][countM] = 0;
values[countS][countM] = 0;
}

if ( analogRead(analogInput) < threshold) {
// macht die umschaltung
if(values[countS][countM] == 0) {
values[countS][countM] = 1;
}
}

dataArrayRED[countS] = values[countS][0]*1+values[countS][1]*2+values[countS][2]*4+values[countS][3]*8+values[countS][4]*16+values[countS][5]*32+values[countS][6]*64+values[countS][7]*128;
//ground latchPin and hold low for as long as you are transmitting
digitalWrite(latchPin, 0);
//move 'em out
shiftOut(dataPin, clockPin, dataArrayGREEN[countS]);
shiftOut(dataPin, clockPin, dataArrayRED[countS]);
//return the latch pin high to signal chip that it
//no longer needs to listen for information
digitalWrite(latchPin, 1);
}
}

}

// the heart of the program
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {

//internal function setup
int i=0;
int pinState;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, OUTPUT);

//clear everything out
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);

for (i=7; i>=0; i-) {
digitalWrite(myClockPin, 0);
if ( myDataOut & (1<<i) ) {
pinState= 1;
}
else {
pinState= 0;
}
//Sets the pin to HIGH or LOW depending on pinState
digitalWrite(myDataPin, pinState);
//register shifts bits on upstroke of clock pin
digitalWrite(myClockPin, 1);
//zero the data pin after shift to prevent bleed through
digitalWrite(myDataPin, 0);
}
//stop shifting
digitalWrite(myClockPin, 0);
}


try it and see what you get cause i have no idea what to change

nkcelectronics

Code: [Select]
rm0 = rowM & 0×01;
rm1 = (rowM>>1) & 0×01;
rm2 = (rowM>>2) & 0×01;

Notice the '×' in 'rm0 = rowM & 0×01;' ?  It is not an 'x'.  It is a smaller x, which is an invalid character in Arduino language (and C).

Replace all 0×01 by 0x01

It is a very subtle difference, if you cannot see it, just delete the existing × and write an x.

ittsuck

Quote
Code: [Select]
rm0 = rowM & 0×01;
rm1 = (rowM>>1) & 0×01;
rm2 = (rowM>>2) & 0×01;

Notice the '×' in 'rm0 = rowM & 0×01;' ?  It is not an 'x'.  It is a smaller x, which is an invalid character in Arduino language (and C).

Replace all 0×01 by 0x01

It is a very subtle difference, if you cannot see it, just delete the existing × and write an x.


thanks that worked perfect i cant belive i missed that thanks......... i got another problem after fixing those X's



In function 'void shiftOut(int, int, byte)':
error: expected primary-expression before ')' token

for (i=7; i>=0; i-) {
digitalWrite(myClockPin, 0);
if ( myDataOut & (1<<i) ) {
pinState= 1;
}
else {
pinState= 0;
}


in this part of the program

westfw

Quote
for (i=7; i>=0; i-) {



You need a double '-':
Code: [Select]
for (i=7; i >= 0; i--) {

nkcelectronics

Yes, the code needs a lot of "cleansing"... like correct datatypes, etc... there are a lot of datatype mixing operations that can make the code compile, but it will be difficult to debug during runtime.  remember that C "promotes" lower datatypes to higher onces during operations, but you need to know exactly what you are doing to get the desired results.

ittsuck

thanks everyone for the help the circuit should work now thanks............

Go Up