[PD-cvs] externals/hardware/arduino/Pd_firmware Pd_firmware.pde, 1.6, 1.7
Hans-Christoph Steiner
eighthave at users.sourceforge.net
Sun May 21 19:37:48 CEST 2006
Update of /cvsroot/pure-data/externals/hardware/arduino/Pd_firmware
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10338/Pd_firmware
Modified Files:
Pd_firmware.pde
Log Message:
its now possible to turn on and off digital and analog input, so you can stop arduino from sending data alltoger, while still responding; digitalInputs are still not tested
Index: Pd_firmware.pde
===================================================================
RCS file: /cvsroot/pure-data/externals/hardware/arduino/Pd_firmware/Pd_firmware.pde,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** Pd_firmware.pde 20 May 2006 16:26:57 -0000 1.6
--- Pd_firmware.pde 21 May 2006 17:37:46 -0000 1.7
***************
*** 25,28 ****
--- 25,37 ----
* 231 - next byte sets PWM1 value
* 232 - next byte sets PWM2 value
+ * 238 - disable all digital inputs
+ * 239 - enable all digital inputs
+ * 240 - disable all analog inputs
+ * 241 - enable 1 analog input (0)
+ * 242 - enable 2 analog inputs (0,1)
+ * 243 - enable 3 analog inputs (0-2)
+ * 244 - enable 4 analog inputs (0-3)
+ * 245 - enable 5 analog inputs (0-4)
+ * 246 - enable 6 analog inputs (0-5)
*
* Pd->Arduino byte cycle
***************
*** 84,87 ****
--- 93,99 ----
int pwmStatus;
+ boolean digitalInputsEnabled = true;
+ byte analogInputsEnabled = 6;
+
byte analogPin;
int analogData;
***************
*** 106,109 ****
--- 118,122 ----
}
else {
+ // TODO: get digital in working
// digitalData = digitalRead(digitalPin);
digitalData = pwmStatus;
***************
*** 152,164 ****
// 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);
for(i=0; i<7; ++i) {
mask = 1 << i;
--- 165,177 ----
// 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);
for(i=0; i<7; ++i) {
mask = 1 << i;
***************
*** 174,178 ****
}
else {
! printByte(161);
// output data for pins 7-13
for(i=7; i<TOTAL_DIGITAL_PINS; ++i) {
--- 187,191 ----
}
else {
! // printByte(161);
// output data for pins 7-13
for(i=7; i<TOTAL_DIGITAL_PINS; ++i) {
***************
*** 190,195 ****
}
else {
! printByte(152);
! printByte(inputData);
switch (inputData) {
case 200:
--- 203,208 ----
}
else {
! // printByte(152);
! // printByte(inputData);
switch (inputData) {
case 200:
***************
*** 231,234 ****
--- 244,262 ----
setPinMode(waitForPWMData, PWM);
break;
+ case 238:
+ digitalInputsEnabled = false;
+ break;
+ case 239:
+ digitalInputsEnabled = true;
+ break;
+ case 240:
+ case 241:
+ case 242:
+ case 243:
+ case 244:
+ case 245:
+ case 246:
+ analogInputsEnabled = inputData - 240;
+ break;
case 255:
firstInputByte = true;
***************
*** 252,276 ****
// -------------------------------------------------------------------------
void loop() {
! /*
! * get analog in
*/
! for(analogPin=0; analogPin<6; ++analogPin)
! {
analogData = analogRead(analogPin);
// these two bytes get converted back into the whole number in Pd
printByte(analogData >> 7); // bitshift the big stuff into the output byte
printByte(analogData % 128); // mod by 32 for the small byte
}
! // read all digital pins
! transmitDigitalInput(0);
! transmitDigitalInput(7);
!
! checkForInput();
!
! /* end with the cycle marker */
! printByte(255);
!
! // setPinMode(13,OUTPUT);
! // digitalWrite(13,HIGH);
}
--- 280,311 ----
// -------------------------------------------------------------------------
void loop() {
! checkForInput();
!
! // read all digital pins, in enabled
! if(digitalInputsEnabled) {
! transmitDigitalInput(0);
! checkForInput();
! transmitDigitalInput(7);
! checkForInput();
! }
! else if(analogInputsEnabled) {
! // filler bytes, since the first thing sent is always the digitalInputs
! printByte(0);
! printByte(0);
! }
!
! /* get analog in, for the number enabled
*/
! for(analogPin=0; analogPin<analogInputsEnabled; ++analogPin) {
analogData = analogRead(analogPin);
// these two bytes get converted back into the whole number in Pd
printByte(analogData >> 7); // bitshift the big stuff into the output byte
printByte(analogData % 128); // mod by 32 for the small byte
+ checkForInput();
}
! /* end with the cycle marker, if any of the inputs are enabled */
! if( digitalInputsEnabled || analogInputsEnabled) {
! printByte(255);
! }
}
More information about the Pd-cvs
mailing list