Issues with repeat function
Elkin
Posts: 58
I am having trouble getting the repeat function to count up for me. either it doesnt ever close the first file, or it goes through them all without logging any data.
I want to insert a function into this code where the (term.rxcheck <> -1) is so that this condition will change within the main block of code (toggling a variable, or a pin)
I have tried a conditional repeat below (repeat while X := 1) and have the variable (X), incrementing and decrementing in my main block, but this wont work.
The goal is to have this block start and stop by command of the main block so that I do not have to hit a key on the computer every time I want to open a new file.
The ZeroPad program is a counting program that can change the number in the string so that the files will not overwrite each other in the SD card (thanks Duane!).
Thanks.
I want to insert a function into this code where the (term.rxcheck <> -1) is so that this condition will change within the main block of code (toggling a variable, or a pin)
I have tried a conditional repeat below (repeat while X := 1) and have the variable (X), incrementing and decrementing in my main block, but this wont work.
The goal is to have this block start and stop by command of the main block so that I do not have to hit a key on the computer every time I want to open a new file.
The ZeroPad program is a counting program that can change the number in the string so that the files will not overwrite each other in the SD card (thanks Duane!).
Thanks.
repeat FileNumber from 0001 to 9999 ZeroPad(FileNumber, 4, @logfile + 4) term.str(@logfile) term.tx(13) check := \sdcard.popen(@logfile, "w") ' attempt to create if (check == 0) term.str(string("-- log file created; logging started", CR)) \sdcard.pputs(@header) ' column header in CSV else term.str(string("-- ERROR: could not create log file", CR)) repeat waitcnt(0) term.rxflush sync := cnt count := 1 repeat while X := 1 read_adc(@ch0) ' get data ' write to log file \sdcard.pputs(dec2str(count, @sbuf)) ' write count \sdcard.pputc(",") ' separate \sdcard.pputs(dec2str(ch0, @sbuf)) ' write ch0 value \sdcard.pputs(@crlf) ' terminate line 'if (term.rxcheck <> -1) ' if key pressed ' quit ' abort waitcnt(sync += clkfreq/10) ' update every 100 milliseconds count += 1 ' update readings count \sdcard.pclose
Comments
Have you put in a term function to print out the value of X to ensure it is 1? (and I mean in your main loop not the one that adjusts the value of X)
Okay, I got it. I went and defined X as a global variable in the VAR block and that took care of the problem. Everything else is the same.
Thanks for the help!
Code now reads:
I had a similar problem with a variable in an object I wrote for a keypad.
My next object I am currently writing runs on 4 cogs with three of the cogs running continuously in repeat statements and taking their instructions from the values of different variables set by other cogs..... (So much could go wrong -- It will be fantastic when it runs smoothly!)