// analog_out.ino // // // Primary computer writes instructions to serial port (COM1, COM2, etc). // Arduino reads from serial port, and outputs that analog voltage. // // 02mar2015, stz -- remove all Serial.print() statements. // these are implicated in serial coms slow-downs! #define PIN_COUNT 10 // using this many digital pins for output #define PIN_BASE 4 // this is the lowest digital pin number used for output #define BIGGEST_WORD (1<= BIGGEST_WORD) w = BIGGEST_WORD - 1; else if(w < 0) w = 0; for(p=0, m=1; p 0) // if bytes are waiting for us in the serial port... { x = Serial.parseFloat(); // try to read them as a floating point number if(x >= OUTMIN && x <= OUTMAX) { y = BIGGEST_WORD * ((x - OUTMIN) / (OUTMAX - OUTMIN)); // range mapping digitalWriteWord((int)y); // express that voltage at the output. } else // out of range { // send an error message back through the serial port. // You won't see this, unless you have opened the Serial Monitor in // the arduino IDE, while the program is running. // found hint online that Serial.print is implicated in // slow-down of serial coms -- don't do this! /** Serial.print("Range Error: asked to output "); Serial.println(x); Serial.print(" OUTMIN = "); Serial.println(OUTMIN); Serial.print(" OUTMAX = "); Serial.println(OUTMAX); **/ } Serial.readBytesUntil('\n',b,BUFLEN); // read & discard newline } } // eof