bjoern avatar bjoern committed 382aea9

changes correspond to release 0005
* BUG FIX: Analog input now reports 8 bits, not just 6 bits
* CHANGE IN BEHAVIOR: when pins are switched to output, they are held low by default (was: high)
* BUG FIX: when PWM messages are received, pins are internally switched to output to avoid extraneous input events from being reported.

Comments (0)

Files changed (1)

 /**************************************************************
- * ARDUINO_OSC 0004
+ * ARDUINO_OSC 0005
  *
  * Firmware to send OSC messages from an Arduino board to a PC
  * and to receive OSC messages sent from the PC.
  * /adc/[0..5] [0..255] - analog input value changed to [0..255]
  * NOTE: input pins use pull-up resistors and are HIGH by default.
  * Therefore, 0 means HIGH, 1 means LOW (pulled to ground). 
+ * Output pins are low by default.
  *
  * EXAMPLES: PC->ARDUINO 
  * /pinmode/5 0         - set pin 5 to INPUT
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  *
- * bjoern@cs.stanford.edu 11/22/2008
+ * bjoern@cs.stanford.edu 12/02/2008
  **************************************************************/
 
-#define VERSION 4
+#define VERSION 5
 
 #define MIN_A2D_DIFF 4  // threshold for reporting a2d changes
 #define MAX_LENGTH 24   // size of buffer for building OSC msgs
   int result;
   int diff;
   // read a2d
-  result = analogRead(channel) >> 2;
+  result = analogRead(channel) >> 2; //only use 8 MSBs
 
   // compare to last reading - if delta big enough,
   // send message
     a2dBuffer[channel]=result;
     strcpy(oscOutAddress,prefixA2d);
     strcat(oscOutAddress,numbers[channel]);
-    oscSendMessageInt(oscOutAddress, (result>>2));
+    oscSendMessageInt(oscOutAddress, result);
   }
 }
 
   if(strncmp(msg,prefixPwm,strlen(prefixPwm))==0) {
     outPin = atoi(msg+strlen(prefixPwm));
     if(outPin>=FIRST_DIGITAL_PIN && outPin<=LAST_DIGITAL_PIN) { //sanity check
+      pinDir = pinDir | (1<<outPin); //turn direction bit to out
+      pinMode(outPin,OUTPUT); // turn DDR bit to output
       analogWrite(outPin,(byte)(value & 0xFF));
     }
     return;
       else {
         pinDir = pinDir | (1<<outPin); //turn bit on
         pinMode(outPin,OUTPUT); // turn DDR bit to output
+        digitalWrite(outPin,LOW); //set LOW by default
       }
     }
     return;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.