[PD-cvs] externals/hardware/arduino/Pd_firmware Pd_firmware.pde, 1.27, 1.28
Hans-Christoph Steiner
eighthave at users.sourceforge.net
Tue Mar 6 07:59:45 CET 2007
Update of /cvsroot/pure-data/externals/hardware/arduino/Pd_firmware
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21760/Pd_firmware
Modified Files:
Pd_firmware.pde
Log Message:
- got digital inputs working reading by port, sends only on change
- ignore Rx/Tx pins (0 and 1) since they are used for serial/USB
- removed a fair amount of cruft
Index: Pd_firmware.pde
===================================================================
RCS file: /cvsroot/pure-data/externals/hardware/arduino/Pd_firmware/Pd_firmware.pde,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** Pd_firmware.pde 5 Mar 2007 17:08:51 -0000 1.27
--- Pd_firmware.pde 6 Mar 2007 06:59:43 -0000 1.28
***************
*** 184,187 ****
--- 184,192 ----
#define PWM 2
+ // for selecting digital inputs
+ #define PB 2 // digital input, pins 8-13
+ #define PC 3 // analog input port
+ #define PD 4 // digital input, pins 0-7
+
#define MAX_DATA_BYTES 2 // max number of data bytes in non-SysEx messages
/* message command bytes */
***************
*** 204,217 ****
/* input message handling */
byte waitForData = 0; // this flag says the next serial input will be data
! byte executeMultiByteCommand = 0; // command to execute after getting multi-byte data
byte multiByteChannel = 0; // channel data for multiByteCommands
byte storedInputData[MAX_DATA_BYTES] = {0,0}; // multi-byte data
/* digital pins */
boolean digitalInputsEnabled = false; // output digital inputs or not
! byte digitalInputHighByte = 0;
! byte digitalInputLowByte = 0;
! byte previousDigitalInputHighByte = 0; // previous output to test for change
! byte previousDigitalInputLowByte = 0; // previous output to test for change
! int digitalPinStatus = 0; // bitwise array to store pin status 0=INPUT,1=OUTPUT
/* PWM/analog outputs */
int pwmStatus = 0; // bitwise array to store PWM status
--- 209,220 ----
/* input message handling */
byte waitForData = 0; // this flag says the next serial input will be data
! byte executeMultiByteCommand = 0; // execute this after getting multi-byte data
byte multiByteChannel = 0; // channel data for multiByteCommands
byte storedInputData[MAX_DATA_BYTES] = {0,0}; // multi-byte data
/* digital pins */
boolean digitalInputsEnabled = false; // output digital inputs or not
! int digitalInputs;
! int previousDigitalInputs; // previous output to test for change
! int digitalPinStatus = 3; // bitwise array to store pin status, ignore RxTx pins
/* PWM/analog outputs */
int pwmStatus = 0; // bitwise array to store PWM status
***************
*** 244,248 ****
// this should be converted to use PORTs
twoBytesForPorts = pin0_6 + (pin7_13 << 7);
! for(i=0; i<14; ++i) {
mask = 1 << i;
if( (digitalPinStatus & mask) && !(pwmStatus & mask) ) {
--- 247,251 ----
// this should be converted to use PORTs
twoBytesForPorts = pin0_6 + (pin7_13 << 7);
! for(i=2; i<TOTAL_DIGITAL_PINS; ++i) { // ignore Rx,Tx pins (0 and 1)
mask = 1 << i;
if( (digitalPinStatus & mask) && !(pwmStatus & mask) ) {
***************
*** 257,261 ****
void checkDigitalInputs(void) {
if(digitalInputsEnabled) {
! // this should use _SFR_IO8()
}
}
--- 260,273 ----
void checkDigitalInputs(void) {
if(digitalInputsEnabled) {
! previousDigitalInputs = digitalInputs;
! digitalInputs = _SFR_IO8(port_to_input[PB]) << 8; // get pins 8-13
! digitalInputs += _SFR_IO8(port_to_input[PD]); // get pins 0-7
! digitalInputs = digitalInputs &~ digitalPinStatus; // ignore pins set OUTPUT
! if(digitalInputs != previousDigitalInputs) {
! // TODO: implement more ports as channels for more than 16 digital pins
! Serial.print(DIGITAL_MESSAGE,BYTE);
! Serial.print(digitalInputs % 128, BYTE); // Tx pins 0-6
! Serial.print(digitalInputs >> 7, BYTE); // Tx pins 7-13
! }
}
}
***************
*** 266,286 ****
*/
void setPinMode(byte pin, byte mode) {
! if(mode == INPUT) {
! digitalPinStatus = digitalPinStatus &~ (1 << pin);
! pwmStatus = pwmStatus &~ (1 << pin);
! digitalWrite(pin,LOW); // turn off pin before switching to INPUT
! pinMode(pin,INPUT);
! }
! else if(mode == OUTPUT) {
! digitalPinStatus = digitalPinStatus | (1 << pin);
! pwmStatus = pwmStatus &~ (1 << pin);
! pinMode(pin,OUTPUT);
! }
! else if( mode == PWM ) {
! digitalPinStatus = digitalPinStatus | (1 << pin);
! pwmStatus = pwmStatus | (1 << pin);
! pinMode(pin,OUTPUT);
! }
// TODO: save status to EEPROM here, if changed
}
--- 278,300 ----
*/
void setPinMode(byte pin, byte mode) {
! if(pin > 1) { // ignore RxTx pins (0,1)
! if(mode == INPUT) {
! digitalPinStatus = digitalPinStatus &~ (1 << pin);
! pwmStatus = pwmStatus &~ (1 << pin);
! digitalWrite(pin,LOW); // turn off pin before switching to INPUT
! pinMode(pin,INPUT);
! }
! else if(mode == OUTPUT) {
! digitalPinStatus = digitalPinStatus | (1 << pin);
! pwmStatus = pwmStatus &~ (1 << pin);
! pinMode(pin,OUTPUT);
! }
! else if( mode == PWM ) {
! digitalPinStatus = digitalPinStatus | (1 << pin);
! pwmStatus = pwmStatus | (1 << pin);
! pinMode(pin,OUTPUT);
! }
// TODO: save status to EEPROM here, if changed
+ }
}
***************
*** 425,434 ****
*============================================================================*/
void loop() {
- ///analogWrite(11, tmp);++tmp;delay(2);
/* DIGITALREAD - as fast as possible, check for changes and output them to the
* FTDI buffer using Serial.print() */
checkDigitalInputs();
if(timer0_overflow_count > nextExecuteTime) {
! nextExecuteTime = timer0_overflow_count + 4; // run this every 4ms
/* SERIALREAD - Serial.read() uses a 128 byte circular buffer, so handle
* all serialReads at once, i.e. empty the buffer */
--- 439,447 ----
*============================================================================*/
void loop() {
/* DIGITALREAD - as fast as possible, check for changes and output them to the
* FTDI buffer using Serial.print() */
checkDigitalInputs();
if(timer0_overflow_count > nextExecuteTime) {
! nextExecuteTime = timer0_overflow_count + 19; // run this every 20ms
/* SERIALREAD - Serial.read() uses a 128 byte circular buffer, so handle
* all serialReads at once, i.e. empty the buffer */
More information about the Pd-cvs
mailing list