/************************************************************************ * DRCtest.c - Test program for Drogon Remote Control. (DRC) * * On the first Arduino: * LEDs are connected to pins nine and eleven, with 560 Ohm current limiting resistors. * A push button switch is connected to pin five, with a 10K pull-down resistor. * A force sensitive resistor is connected to analog pin zero, with a 10K pull-down resistor. * The only connection to the RaspberryPi is the USB cable. * The program in the RaspberryPi is controling the Arduino. * The DRC.ino program must be installed and running. * * Nothing is connected to the second Arduino. * * On the RaspberryPi: * LEDs are connected to pins nine and eleven, with 560 Ohm current limiting resistors. * A push button switch is connected to pin five, with a 10K pull-down resistor. * The pin numbers for the RaspberryPi use the wiringPi pin numbering scheme. * * The loop() function does a digitalRead of the push button on the Arduino * and digitalWrites the value to the both red LEDs * Next it performs an analogRead of the force sensitive resistor, divides * the value by four, and pwmWrites the value to both green LEDs. * Then is does a digitalRead of the push button on the RaspberryPi * and digitalWrites the value to the both red LEDs * ************************************************************************/ #include #include #include #define BASE 100 #define BASE2 200 /***************************************************************************** * The second thread blinks the built in LED on pin 13 of the Second Arduino. * The code here runs concurrently with the main program in an infinite loop. *****************************************************************************/ PI_THREAD(arduino2) { for(;;) { digitalWrite(BASE2+13, HIGH); // Turn pin 13 on. delay(500); digitalWrite(BASE2+13, LOW); // Turn pin 13 off. delay(500); } } /************************************************************************** * setup() function **************************************************************************/ void setup(void) { wiringPiSetup(); drcSetupSerial(BASE, 20, "/dev/ttyACM0", 115200); drcSetupSerial(BASE2, 20, "/dev/ttyACM1", 115200); int x = piThreadCreate(arduino2); // Start second thread. if (x != 0) printf("It didn't start.\n"); // Pins on Arduino: pinMode (BASE+11, PWM_OUTPUT); // Reset pin to maximum value pwmWrite(BASE+11, 255); // after PWM write. pinMode (BASE+5, INPUT); // Pin 5 used for digitalRead. pinMode (BASE+9, PWM_OUTPUT); // Pin 9 used for pwmWrite. // Pin A0 is used for analogRead. // Pins on second Arduino: pinMode (BASE2+13, OUTPUT); // Pin 13 used for digitalWrite. // Pins on RaspberryPi: pinMode(0, OUTPUT); // Pin 0 used for digitalWrite. pinMode(5, INPUT); // Pin 5 used for digitalRead. pinMode(1, PWM_OUTPUT); // Pin 1 used for pwmWrite. } /************************************************************************** * loop() function **************************************************************************/ void loop(void) { digitalWrite(BASE+11, digitalRead(BASE+5)); // If Arduino button is pressed digitalWrite(0, digitalRead(BASE+5)); // turn on both red LEDs. pwmWrite(BASE+9, (analogRead(BASE)/4)); // Varies the brightness of both green pwmWrite(1, (analogRead(BASE)/4)); // LEDs according to pressure applied // to the force sensitive resistor. digitalWrite(BASE+11, digitalRead(5)); // If RaspberryPi button is pressed digitalWrite(0, digitalRead(5)); // turn on both red LEDs. } /************************************************************************** * main() function **************************************************************************/ int main (void) { setup(); for(;;) { loop(); } return 0 ; }