Update of /cvsroot/pure-data/externals/hardware/arduino/Pd_firmware In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2211/Pd_firmware
Modified Files: Pd_firmware.pde Log Message: its messy, but digital output and PWM now work at the same time
Index: Pd_firmware.pde =================================================================== RCS file: /cvsroot/pure-data/externals/hardware/arduino/Pd_firmware/Pd_firmware.pde,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Pd_firmware.pde 20 May 2006 10:18:14 -0000 1.3 --- Pd_firmware.pde 20 May 2006 15:29:48 -0000 1.4 *************** *** 20,25 **** * Pd->Arduino commands * -------------------- ! * 200-213 - set digital pin 0-13 to output ! * 214-227 - set digital pin 0-13 to input * 230 - next byte sets PWM0 value * 231 - next byte sets PWM1 value --- 20,25 ---- * Pd->Arduino commands * -------------------- ! * 200-213 - set digital pin 0-13 to INPUT ! * 214-227 - set digital pin 0-13 to OUTPUT * 230 - next byte sets PWM0 value * 231 - next byte sets PWM1 value *************** *** 67,72 **** #define PWM 2
! // this flag says the next serial input will be data, not control ! boolean waitForData = false;
// this flag says the first data byte for the digital outs is next --- 67,72 ---- #define PWM 2
! // this flag says the next serial input will be PWM data ! byte waitForPWMData = 0;
// this flag says the first data byte for the digital outs is next *************** *** 130,135 **** } else if( (mode == PWM) && (pin >= 9) && (pin <= 11) ) { ! digitalPinStatus = digitalPinStatus &~ (1 << pin); pwmStatus = pwmStatus | (1 << pin); } } --- 130,136 ---- } else if( (mode == PWM) && (pin >= 9) && (pin <= 11) ) { ! digitalPinStatus = digitalPinStatus | (1 << pin); pwmStatus = pwmStatus | (1 << pin); + pinMode(pin,OUTPUT); } } *************** *** 139,143 **** if(serialAvailable()) { while(serialAvailable()) { ! processInput(serialRead()); } } --- 140,144 ---- if(serialAvailable()) { while(serialAvailable()) { ! processInput( (byte)serialRead() ); } } *************** *** 145,163 ****
// ------------------------------------------------------------------------- ! void processInput(int inputData) { // the PWM commands (230-232) have a byte of data following the command ! if (waitForData > 0) { printByte(150); printByte(inputData); ! analogWrite(waitForData,inputData); ! waitForData = 0; } ! else if(inputData < 128) { printByte(151); ! printByte(inputData); ! // TODO: this section is for digital out... } else { ! printByte(153); switch (inputData) { case 200: --- 146,208 ----
// ------------------------------------------------------------------------- ! void processInput(byte inputData) { ! byte i; ! int mask; ! // byte writeTest; ! // byte highDigitalPinStatus; ! // the PWM commands (230-232) have a byte of data following the command ! if (waitForPWMData > 0) { printByte(150); printByte(inputData); ! analogWrite(waitForPWMData,inputData); ! waitForPWMData = 0; } ! else if(inputData < 128) { printByte(151); ! if(firstInputByte) { ! printByte(160); ! printByte(inputData); ! // TODO: this section is for digital out... ! for(i=0; i<7; ++i) { ! mask = 1 << i; ! /* writeTest = digitalPinStatus; ! // writeTest = writeTest & mask; ! // printByte(writeTest); ! // if(writeTest) { ! // or ! /* if((byte)digitalPinStatus & mask) { ! // digitalWrite(i,(inputData & mask) >> i); ! printByte(254); ! printByte(i); ! printByte(mask); ! printByte(inputData & mask); ! } */ ! } ! firstInputByte = false; ! } ! else { ! printByte(161); ! printByte(inputData); ! // output data for pins 7-13 ! //highDigitalPinStatus = digitalPinStatus >> 7; ! for(i=7; i<TOTAL_DIGITAL_PINS; ++i) { ! mask = 1 << i; ! printByte(254); ! printByte(i); ! printByte(mask); ! // if(digitalPinStatus & mask) { ! // need to add test for pwmStatus ! if( (digitalPinStatus & mask) && !(pwmStatus & mask) ) { ! digitalWrite(i, inputData & (mask >> 7)); ! printByte(inputData & (mask >> 7)); ! // printByte(highDigitalPinStatus & mask); ! } ! } ! } } else { ! printByte(152); ! printByte(inputData); switch (inputData) { case 200: *************** *** 175,180 **** case 212: case 213: ! printByte(inputData); ! setPinMode(inputData-200,OUTPUT); break; case 214: --- 220,224 ---- case 212: case 213: ! setPinMode(inputData-200,INPUT); break; case 214: *************** *** 192,206 **** case 226: case 227: ! printByte(inputData); ! setPinMode(inputData-214,INPUT); break; case 230: case 231: case 232: ! printByte(inputData); ! waitForData = inputData - 221; // set waitForData to the PWM pin number ! setPinMode(waitForData, PWM); break; case 255: break; } --- 236,249 ---- case 226: case 227: ! setPinMode(inputData-214,OUTPUT); break; case 230: case 231: case 232: ! waitForPWMData = inputData - 221; // set waitForPWMData to the PWM pin number ! setPinMode(waitForPWMData, PWM); break; case 255: + firstInputByte = true; break; } *************** *** 223,228 **** void loop() { // read all digital pins ! transmitDigitalInput(0); ! transmitDigitalInput(7); /* * get analog in --- 266,271 ---- void loop() { // read all digital pins ! //transmitDigitalInput(0); ! //transmitDigitalInput(7); /* * get analog in *************** *** 242,250 **** // bitshift the big stuff into the output byte printByte(digitalPinStatus >> 7); ! // clear the 8th bit before truncating to a byte for small byte printByte(digitalPinStatus % 128);
checkForInput();
! printByte(255); } --- 285,298 ---- // bitshift the big stuff into the output byte printByte(digitalPinStatus >> 7); ! // clear the 8th bit before truncating to a byte for small data byte printByte(digitalPinStatus % 128);
+ printByte(pwmStatus >> 7); + printByte(pwmStatus % 128); + checkForInput();
! printByte(255); ! setPinMode(13,OUTPUT); ! digitalWrite(13,HIGH); }