/* * Author: Alberto Machado * Project: Palm Harvester * Year: Fall 2015-Spring 2016 * Description: This code uses the Arduino transmitter as shown * in the report. It uses the "RCSwitch" library and it transmit * various number depending on user input. */ #include RCSwitch mySwitch = RCSwitch(); const int left = 100; const int down = 100; const int right = 900; const int up = 900; const int button_A = 2; // Port 2 connected to button A const int button_B = 3; // Port 3 connected to button B const int button_C = 4; // Port 4 connected to button C const int button_D = 5; // Port 5 connected to button D const int button_E = 6; // Port 6 connected to button E const int button_F = 7; // Port 7 connected to button F void setup() { Serial.begin(15200); //Transmitter is connected to Pin 10 mySwitch.enableTransmit(10); // Set all button pins to Input pinMode(button_A, INPUT); pinMode(button_B, INPUT); pinMode(button_C, INPUT); pinMode(button_D, INPUT); pinMode(button_E, INPUT); pinMode(button_F, INPUT); } void loop() { int sensorValx = analogRead(A0); // Read value from Analog port A0 (X value) int sensorValy = analogRead(A1); // Read value from Analog port A1 (Y value) if(sensorValx < left) // Transmit the number 2 when joystick moves left mySwitch.send("000000000000000000000010"); else if(sensorValy < down) // Transmit the number 3 when joystick moves down mySwitch.send("000000000000000000000011"); else if(sensorValx > right) // Transmit the number 4 when joystick moves right mySwitch.send("000000000000000000000100"); else if(sensorValy > up) // Transmit the number 5 when joystick moves up mySwitch.send("000000000000000000000101"); else if(digitalRead(button_A) == LOW)// Transmit the number 6 when button A is pressed mySwitch.send("000000000000000000000110"); else if(digitalRead(button_B) == LOW)// Transmit the number 7 when button B is pressed mySwitch.send("000000000000000000000111"); else if(digitalRead(button_C) == LOW)// Transmit the number 8 when button C is pressed mySwitch.send("000000000000000000001000"); else if(digitalRead(button_D) == LOW)// Transmit the number 9 when button D is pressed mySwitch.send("000000000000000000001001"); else if(digitalRead(button_E) == LOW)// Transmit the number 10 when button E is pressed mySwitch.send("000000000000000000001010"); else if(digitalRead(button_F) == LOW)// Transmit the number 11 when button F is pressed mySwitch.send("000000000000000000001011"); else // Transmit the number 1 when no button is pressed mySwitch.send("000000000000000000000001"); }