Go Down

Topic: storing to memory in one function to use in another (Read 1 time) previous topic - next topic


Normally, when I see a switch/case being used with individual variable names, I think "array", in this case, a two-dimensional array. It'll make the code a lot shorter.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.


Code: [Select]
  delay (1000);// delay
Why? There is no reason at all to delay() as the first thing in setup().

Code: [Select]
  Serial.begin(9600);//initialize serial communications at 9600 bps:

Block until all sent data has been shifted out. You have not sent anything. The flush() call is useless.

Code: [Select]


i have uploaded my code as it is too big to put on here.

i am still getting the same problem

serial monitor result:
items:0  total0.00
Hienz baked beans 
items:1  total0.10
pint skimmed milk 
items:2  total0.60
loaf white bread   
items:3  total1.30
pint skimmed milk  loaf white bread   6 eggs             
loaf white bread   6 eggs             
6 eggs             
items:4  total1.55
loaf white bread   6 eggs             Hienz baked beans 
6 eggs             Hienz baked beans 
Hienz baked beans 
items:5  total1.65

and the output to the display is fine until case 3 where it display

6eggs    //(its meant to be pink skimmed milk)
loaf white bread

the same happens on case 4, it displays

Hienz baked beans  //(should be loaf white bread)
6 eggs           
Hienz baked beans

any ideas why it does this and how i could change it?

ps, sorry if my code doesnt read well, only got arduino 2 weeks ago so still trying to figure it all out


Code: [Select]
  if (Serial.available() > 0)//if a card is swiped read incoming rx number from rfid tag
    for (int z=0; z<16; z++)//start at z=0 then add number for every number that comes in from tag
      data=Serial.read();//input numbers from rf id and store into data
      newcard[z] = data;// store number from data into array of z long in newcard
      Serial.flush();//stops multiple reads
      delay (50);

This is still crap. You have been told that before. If there is ONE byte of serial data to read, and that is all that is required to be in the buffer when the if test evaluates to true, you can NOT read all of the the one characters.

You do not need the flush() call. Period. Get rid of it.

Get rid of all the crap that writes to the LCD until you KNOW that the data in line1, line2, line3, line4, and line5 is correct.

The arrays line1, line2, line3, line4, and line5 are NOT strings, so passing them to functions that expect strings is an exercise in futility.

Get a book on C and research the difference between a string and a char array. Then, fix your code so that it NULL terminates the char arrays, making them strings. Oops, I think I gave it away...

Go Up