Buy an Axon, Axon II, or Axon Mote and build a great robot, while helping to support SoR.
0 Members and 2 Guests are viewing this topic.
//grab commands from keyboardif(uartGetByte() == '1') do_something=1;if(uartGetByte() == '2') do_something=2;if(uartGetByte() == '3') do_something=3;if(uartGetByte() == '4') do_something=4;uartFlushReceiveBuffer();//flushes out entire recieve buffer
do_something=uartGetByte();
unsigned int current=98;rprintf("Current: %u \r\n", current);
unsigned int current=98;rprintf("Current: %d \r\n", current);
ch = uartGetByte ();if (ch == '1') do_something_oneelse if (ch == '2') do_something_two
data = uartGetByte();if(data == '1') do_something=1;if(data == '2') do_something=2;if(data == '3') do_something=3;if(data == '4') do_something=4;
And is there a nicer way to write this code? For example:Code:do_something=uartGetByte();
int doSomethingWithByte(char* cc){ data = uartGetByte(); if(data == '1') cc = "one something"; return 1; else if(data == '2') cc = "two somethings"; return 2; return 0 ;}int main(void){ unsigned char cc ; // this will contain the output from doSomethingWithByte() after it has run // this is your main section // while(1){ if (doSomethingWithByte(cc)){ // put code to do something with cc in here. } }
The other problem is with printing out variable values. If I do thisCode:unsigned int current=98;rprintf("Current: %u \r\n", current);then I get this in hyperterminal: 'Current: u'But if I do thisCode:unsigned int current=98;rprintf("Current: %d \r\n", current);then I get this in hyperterminal: 'Current: 98' (correct)It just doesnt make sense to me why I can't use %u . . .
#ifdef RPRINTF_SIMPLE //! A simple printf routine. /// Called by rprintf() - does a simple printf (supports %d, %x, %c). /// Supports: /// - %d - decimal /// - %x - hex /// - %c - character int rprintf1RamRom(unsigned char stringInRom, const char *format, ...); // #defines for RAM or ROM operation #define rprintf1(format, args...) rprintf1RamRom(STRING_IN_ROM, PSTR(format), ## args) #define rprintf1RAM(format, args...) rprintf1RamRom(STRING_IN_RAM, format, ## args) // *** Default rprintf(...) *** // this next line determines what the the basic rprintf() defaults to: #define rprintf(format, args...) rprintf1RamRom(STRING_IN_ROM, PSTR(format), ## args)#endif#ifdef RPRINTF_COMPLEX //! A more powerful printf routine. /// Called by rprintf() - does a more powerful printf (supports %d, %u, %o, %x, %c, %s). /// Supports: /// - %d - decimal /// - %u - unsigned decimal /// - %o - octal /// - %x - hex /// - %c - character /// - %s - strings /// - and the width,precision,padding modifiers /// \note This printf does not support floating point numbers. int rprintf2RamRom(unsigned char stringInRom, const char *sfmt, ...); // #defines for RAM or ROM operation #define rprintf2(format, args...) rprintf2RamRom(STRING_IN_ROM, format, ## args) #define rprintf2RAM(format, args...) rprintf2RamRom(STRING_IN_RAM, format, ## args) // *** Default rprintf(...) *** // this next line determines what the the basic rprintf() defaults to: #define rprintf(format, args...) rprintf2RamRom(STRING_IN_ROM, PSTR(format), ## args)#endif
try something like this:Code: [Select]data = uartGetByte();if(data == '1') do_something=1;if(data == '2') do_something=2;if(data == '3') do_something=3;if(data == '4') do_something=4;
int data=0;data = uartGetByte();switch (data) { case 32: do_something=0; break; case 33: do_something=1; break;etc...up to 41 default: do_something=(some default value you select);}