/* * Author: Alberto Machado * Project: Palm Harvester * Year: Fall 2015 - Spring 2016 * Description: This code is used for the arduino attached on the cart. * It moves the telescoping pole up and down. Uses the receiver functions from * the RCSwitch library to receive the wireless signal from the transmitter and uses those values * to move the pole either up or down. */ #include RCSwitch mySwitch = RCSwitch(); const int button_C = 8; //value received from controller when button C is pressed const int button_D = 9; //value received from controller when button D is pressed const int pwm = 11; //port on the Arduino used to connect to the "pwm" port of the motor driver const int dir = 13; //port on the Arduino used to connect to the "dir" port of the motor driver const int microsec_delay = 2000; // delay in microseconds of the winch depicting how long it'll be on void setup() { Serial.begin(115200); mySwitch.enableReceive(0); // Receiver pin 2 // set both ports to output pinMode(pwm, OUTPUT); pinMode(dir, OUTPUT); } void loop() { if(mySwitch.available()) { int value = mySwitch.getReceivedValue(); if(value == button_C) // when button C is pressed { // moves pole up digitalWrite(dir, LOW); // set dir to LOW digitalWrite(pwm, HIGH); // turn on winch delay(microsec_delay); // Software delay in microseconds digitalWrite(pwm, LOW); // turn off winch } else if(value == button_D) // when button D is pressed { // moves pole down digitalWrite(dir, HIGH); // set dir to HIGH digitalWrite(pwm, HIGH); // turn on winch delay(microsec_delay); // Software delay in microseconds digitalWrite(pwm, LOW); // turn off winch } else // if neither buttons are pressed digitalWrite(pwm, LOW); // turn off winch } }