From 251ea5facdf2df8411bbaead9bc1d2e6be2ad784 Mon Sep 17 00:00:00 2001 From: Richard Stanley Date: Sun, 26 Nov 2017 12:22:49 -0800 Subject: [PATCH 1/2] Nvidia Joystick port for python3.5 and sysfs GPIO support --- .../NvidiaJoystick_SocketCall.py | 339 ++++++++++++++++++ 1 file changed, 339 insertions(+) create mode 100755 rover/core/servers/ArduinoSocketServer/NvidiaJoystick_SocketCall.py diff --git a/rover/core/servers/ArduinoSocketServer/NvidiaJoystick_SocketCall.py b/rover/core/servers/ArduinoSocketServer/NvidiaJoystick_SocketCall.py new file mode 100755 index 00000000..5a0dd75d --- /dev/null +++ b/rover/core/servers/ArduinoSocketServer/NvidiaJoystick_SocketCall.py @@ -0,0 +1,339 @@ +#!/bin/sh + +### BEGIN INIT INFO +# Provides: RoverMobilityServer +# Required-Start: $remote_fs $network $syslog +# Required_Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Simple script to start a program at boot +# Description: Rover Mobility Server +### END INIT INFO + +from socket import * +from datetime import datetime +import time +import pygame +#import RPi.GPIO as GPIO + +# WAIT FOR STUFF +time.sleep(5) + +#LED Signals for status +#GPIO.setmode(GPIO.BCM) +#GPIO.setwarnings(False) +redLed = 18 +greenLed = 23 +blueLed = 24 +#GPIO.setup(redLed, GPIO.OUT) #Red LED +#GPIO.setup(greenLed, GPIO.OUT) #Green LED +#GPIO.setup(blueLed, GPIO.OUT) #Blue LED + +pygame.init() + +# Initialize the joysticks +pygame.joystick.init() + +# Arduino address and connection info +address = ('192.168.1.177', 5000) +client_socket = socket(AF_INET, SOCK_DGRAM) +#client_socket.settimeout(.5) + +# Globals variables for data transmittion +global re_data +re_data = "" +global data +data = "" + +# Globals for motor output +global motor2 +motor2 = 0 +global motor1 +motor1 = 0 +global pauseInterval +pauseInterval = 0 +global pauseQuitInterval +pauseQuitInterval = 0 +global pauseFull +pauseFull = False +global modeWhenPaused +modeWhenPaused = "" + +#global motor1, motor2, pauseInterval, pauseQuitInterval, modeWhenPause, motor_mult, arm1, arm2, joint5, joint6, joint7, mode + +# Global variable for motor throttle +global motor_mult +motor_mult = .5 + +# Globals variables for Arm and Joints +global arm1 +arm1 = 0 +global arm2 +arm2 = 0 +global joint5 +joint5 = 0 +global joint6 +joint6 = 0 +global joint7 +joint7 = 0 + +global mode +mode = "both" + +# Initialize the connection to Arduino +client_socket.sendto('0,0', address) + +def stop(): + try: + re_data, addr = client_socket.recvfrom(2048) + + if re_data == "ready": + data = str(0) + ',' + str(0) + ',' + str(0) + ',' + str(0) + ',' + str(0) + ',' + str(0) + ',' + str(0) + ',' + str(0) + ',' + str(0) + ',' + str(0) + joint1 = joint5 = joint6 = joint7 = 0 + client_socket.sendto(data, address) + print("Sent Stop Command") + except: + print("Failed to send Stop Command") + pass + return; + +# This function changes the color of the LED on the Pi, based off of the current mode the rover is in +# Green meaning BOTH Mobility and Arm are active +# Blue meaning ONLY Mobility is active +# Purple meaning ONLY Arm is active +# Red meaning NEITHER Mobility or Arm is actice, we are in a paused state +# Input: NONE +# Output: NONE +#def changeLedColor(): + #if mode == "both": + #LED Color = Green + #GPIO.output(greenLed,GPIO.HIGH) + #GPIO.output(redLed,GPIO.LOW) + #GPIO.output(blueLed,GPIO.LOW) + #elif mode == "mobility": + #LED Color = Blue + #GPIO.output(greenLed, GPIO.LOW) + #GPIO.output(redLed, GPIO.LOW) + #GPIO.output(blueLed, GPIO.HIGH) + #elif mode == "arm": + #LED Color = Purple + #GPIO.output(greenLed, GPIO.LOW) + #GPIO.output(redLed,GPIO.HIGH) + #GPIO.output(blueLed,GPIO.HIGH) + #elif mode == "pause": + #LED Color = Red + #GPIO.output(redLed,GPIO.HIGH) + #GPIO.output(greenLed,GPIO.LOW) + #GPIO.output(blueLed,GPIO.LOW) + +# This function takes in a joystick and reads the values of each joystick Axis. +# Based on the values of the joystick axis it sets the corresponding motor values +# to be sent to the ESC. +# Input: Joystick +# Output: None +def checkJoystickMovement(currentJoystick): + global motor1, motor2, pauseInterval, pauseQuitInterval, modeWhenPause, motor_mult, arm1, arm2, joint5, joint6, joint7, mode + axes = currentJoystick.get_numaxes() + + # Check for axes usage + for i in range( axes ): + axis = joystick.get_axis( i ) + if mode == "mobility" or mode == "both": + if i == 1: + motor1 = -int(127 * axis * motor_mult) + if i == 0: + motor2 = int(127 * axis * motor_mult) + if mode == "arm" or mode == "both": + if i == 2: + arm1 = int(127 * axis) + if i == 3: + arm2 = int(127 * axis) + +# This function takes in a joystick and cycles through all of the buttons to see if any are pushed. +# If any are pushed it sets the corresponding command to the rover. +# Input: Joystick +# Output: None +# List of Buttons and what they move (Logitech Wireless Controller). +# Button 1: Joint 5.1 Rotate End Effector Left +# Button 2: Joint 4 Move Up +# Button 3: Joint 5.1 Rotate End Effector Right +# Button 4: Joint 4 Move Down +# Button 5: Joint 5.2 Close End Effector +# Button 6: Joint 5.2 Open End Effector +# Button 7: Decrease Motor Multiplier +# Button 8: Increase Motor Multiplier +# Button 9: Pause/Unpause Rover commands +# Button 10: Switch between modes +# Note: These button numbers are as they are on the controller. +# In the for loop the buttons go from 0-9 not 1-10 +def checkButtons(currentJoystick): + global motor1, motor2, pauseInterval, pauseQuitInterval, modeWhenPause, motor_mult, arm1, arm2, joint5, joint6, joint7, mode, modeWhenPaused + #Get the number of buttons on the joystick + buttons = currentJoystick.get_numbuttons() + + # Cycle through every button set corresponding values depending on whether button is pushed or not. + # Set the corresponding joint values if buttons 1-6 + # Adjust the motor multiplier if buttons 7,8 + # Pause/Unpause rover if Button 9 + # Switch modes if Button 10 + for i in range( buttons ): + #Gets whether button is pushed or not (0 = not pushed, 1 = pushed) + button = joystick.get_button( i ) + + #If arm is active set joint values + if mode == "both" or mode == "arm": + # Joint commands + if i == 1: + joint5 = button + elif i == 3 and joint5 == 0: + joint5 = -button + + if i == 0: + joint6 = button + elif i == 2 and joint6 == 0: + joint6 = -button + + if i == 4: + joint7 = button + elif i == 5 and joint7 == 0: + joint7 = -button + + # If mobility is active change multiplier if buttons are pushed + if mode == "both" or mode == "mobility": + # Motor Multiplier Commands + if i == 6 and button == 1 and motor_mult > 0.31: + motor_mult = motor_mult - .1 + print(motor_mult) + + if i == 7 and button == 1 and motor_mult < .9: + motor_mult = motor_mult + .1 + print(motor_mult) + + # If Pause button is held down for atleast 3 seconds pause/unpause + if i == 9 and button == 1: + if pauseQuitInterval == 0: + pauseQuitInterval = datetime.now() + elif (datetime.now() - pauseQuitInterval).seconds > 3: + if mode != "pause": + print("Pausing Controls") + + #Keeps mode when paused so we can return to the same mode + modeWhenPaused = mode + mode = "pause" + pauseQuitInterval = 0 + stop() + #changeLedColor() + elif mode == "pause": + print("Resuming Controls") + mode = modeWhenPaused + modeWhenPaused = "" + pauseQuitInterval = 0 + #changeLedColor() + elif i == 9 and button == 0 and pauseQuitInterval !=0: + print("Reseting Pause Interval") + pauseQuitInterval = 0 + + #This button switches between different Modes + #Green = Arm and Mobility + #Blue = Mobility + #Purple = Arm + #Red = None (Paused) + if i == 8 and button == 1: + #print(pauseInterval) + if pauseInterval == 0: + pauseInterval = datetime.now() + elif mode == "both": + if (datetime.now() - pauseInterval).seconds > 3: + print("Switching to MOBILITY ONLY mode") + mode = "mobility" + #stop() + pauseInterval = 0 + #LED color = Blue + #changeLedColor() + elif mode == "mobility": + if (datetime.now() - pauseInterval).seconds > 3: + print("Switcching to ARM ONLY mode") + #stop() + mode = "arm" + pauseInterval = 0 + #LED Color = Purple + #changeLedColor() + elif mode == "arm": + if (datetime.now() - pauseInterval).seconds > 3: + print("Switching to BOTH mode") + #stop() + mode = "both" + pauseInterval = 0 + #LED Color = Green + #changeLedColor() + elif i == 8 and button == 0 and pauseInterval != 0: + print("reseting Pause Interval") + pauseInterval = 0 + +def checkHats(currentJoystick): + global motor1, motor2, pauseInterval, pauseQuitInterval, modeWhenPause, motor_mult, arm1, arm2, joint5, joint6, joint7, mode + hats = currentJoystick.get_numhats() + + if mode == "arm" or mode == "both": + for i in range( hats ): + hat = joystick.get_hat( i ) + if hat[0] != 0: + joint1 = hat[0] + else: + joint1 = 0 + +#Depending on which mode we are in only the correct buttons will be checked +while(1): + #changeLedColor() + for event in pygame.event.get(): # User did something + # Possible joystick actions: JOYAXISMOTION JOYBALLMOTION JOYBUTTONDOWN JOYBUTTONUP JOYHATMOTION + if event.type == pygame.JOYBUTTONDOWN: + print("Joystick button pressed.") + if event.type == pygame.JOYBUTTONUP: + print("Joystick button released.") + + # Get count of joysticks + joystick_count = pygame.joystick.get_count() + + # Sends Shutdown motor and arm commands if joystick is lost + if joystick_count == 0: + stop() + + # For each joystick: + for i in range(joystick_count): + joystick = pygame.joystick.Joystick(i) + joystick.init() + + # Get the name from the OS for the controller/joystick + name = joystick.get_name() + + checkJoystickMovement(joystick) + checkButtons(joystick) + checkHats(joystick) + + # Command to Arduino + if mode != 'pause': + print('Sending Command to Arduino') + try: + if mode == 'both': + data = str(motor1) + ',' + str(motor2) + ',' + str(arm1) + ',' + str(arm2) + ',' + str(joint1) + ',' + str(joint5) + ',' + str(joint6) + ',' + str(joint7) + ',' + '0' + ',' + '0' + elif mode == 'arm': + data = '0' + ',' + '0' + ',' + str(arm1) + ',' + str(arm2) + ',' + str(joint1) + ',' + str(joint5) + ',' + str(joint6) + ',' + str(joint7) + ',' + '0' + ',' + '0' + elif mode == 'mobility': + data = str(motor1) + ',' + str(motor2) + ',' + '0' + ',' + '0' + ',' + '0' + ',' + '0' + ',' + '0' + ',' + '0' + ',' + '0' + ',' + '0' + elif mode == 'pause': + data = '0' + ',' + '0' + ',' + '0' + ',' + '0' + ',' + '0' + ',' + '0' + ',' + '0' + ',' + '0' + ',' + '0' + ',' + '0' + print (data) + re_data, addr = client_socket.recvfrom(2048) + print (re_data) + + if re_data == "ready": + #data = str(motor1) + ',' + str(motor2) + ',' + str(arm1) + ',' + str(arm2) + ',' + str(joint1) + ',' + str(joint5) + ',' + str(joint6) + ',' + str(joint7) + ',' + '0' + ',' + '0' + client_socket.sendto(data, address) + print (data) + except: + print('Failed') + pass + # Safety catch to force new values or shutdown old ones + data = str(0) + ',' + str(0) + ',' + str(0) + ',' + str(0) + ',' + str(0) + ',' + str(0) + ',' + str(0) + ',' + str(0) + ',' + str(0) + ',' + str(0) + joint1 = joint5 = joint6 = joint7 = motor1 = motor2 = arm1 = arm2 = 0 From e3033ed970ae63198cf537c908838d19f8532509 Mon Sep 17 00:00:00 2001 From: Jithin Eapen Date: Tue, 19 Dec 2017 21:13:02 -0800 Subject: [PATCH 2/2] ArduinoLEDcolor Arduino LED color changes as per mode --- .../ArduinoSocketServer.ino | 286 ++++++++---------- 1 file changed, 129 insertions(+), 157 deletions(-) diff --git a/rover/core/servers/ArduinoSocketServer/ArduinoSocketServer.ino b/rover/core/servers/ArduinoSocketServer/ArduinoSocketServer.ino index 4ee0166e..68a56478 100644 --- a/rover/core/servers/ArduinoSocketServer/ArduinoSocketServer.ino +++ b/rover/core/servers/ArduinoSocketServer/ArduinoSocketServer.ino @@ -9,107 +9,31 @@ */ #include -//#include -#include -#include -//#include - -const int stepsPerRevolution = 200; -// X Axis Mobility -/*Servo x_mobility; - const uint8_t x_pwm_pin = 6; - - // Y Axis Mobility - Servo y_mobility; - const uint8_t y_pwm_pin = 7;*/ +//#include +//#include // Joint #1 -const uint8_t joint1_dir_pin = 23; +const uint8_t joint1_pulse_pin = 2; +const uint8_t joint1_dir_pin = 6; const uint8_t joint1_enab_pin = 31; -const uint8_t joint1_pulse_pin = 11; - -//volatile bool joint1_on = false; -//const uint8_t joint1_limit_pin = A0; -//unsigned int joint1_sensorValue; -//uint8_t joint1_bit; -//uint8_t joint1_port; -//const int upperLimit = 630; -//const int lowerLimit = 55; -//const int middlePoint = 346; -//volatile bool centerJoint1 = false; -// -//// Joint #2 -//Servo joint2; -//const uint8_t joint2_pwm_pin = 4; -// -//// Joint #3 -//Servo joint3; -//const uint8_t joint3_pwm_pin = 5; -// -//// Joint #4 -//const uint8_t joint4_dir_pin = 32; -//const uint8_t joint4_enab_pin = 35; -//const uint8_t joint4_pulse_pin = 36; -//volatile bool joint4_on = false; -//volatile bool joint4_interrupted = false; -//volatile bool joint4_needsStepOff = false; -//const uint8_t joint4_interrupt_pin = 3; -//unsigned long joint4_TotalSteps = 0; -//uint8_t joint4_bit; -//uint8_t joint4_port; -//const unsigned long joint4_StepsLimit = 7330; -//bool joint4passedLimit = false; -//const int joint4_LimitDistance_Steps = 100; -// -//// Joint #5 -const uint8_t joint5_dir_pin = 27; -//const uint8_t joint5_enab_pin = 39; -const uint8_t joint5_pulse_pin = 26; -//volatile bool joint5_on = false; -//volatile bool joint5_interrupted = false; -//volatile bool joint5_needsStepOff = false; -//const uint8_t joint5_interrupt_pin = 2; -//unsigned long joint5_TotalSteps = 0; -//uint8_t joint5_bit; -//uint8_t joint5_port; -//const unsigned long joint5_StepsLimit = 50500; -//bool joint5passedLimit = false; -//const int joint5_LimitDistance_Steps = 1000; -// -//// Joint #6 -//AMIS30543 joint6_stepper; -//const uint8_t joint6_ss = 44; -//const uint8_t joint6_dir_pin = 42; -//const uint8_t joint6_pulse_pin = 43; -//volatile bool joint6_on = false; -// -//// Joint #7 -//AMIS30543 joint7_stepper; -//const uint8_t joint7_ss = 48; -const uint8_t joint7_dir_pin = 25; -const uint8_t joint7_pulse_pin = 24; -//volatile bool joint7_on = false; -// -//// AssAss globals -//Servo AssAss; -//const uint8_t assass_pwm_pin = 9; - -// Additional Global variables needed -uint8_t val[6]; -int i; -int delayVal = 1; -uint16_t pwmVal; -const int interruptDelay = 350; -const int ignoreDelay = 250; -static unsigned long ignore_time = 0; -static unsigned long last_interrupt_time = 0; - -bool Calibrated = false; // Arm can't be moved until calibrated -bool debug = false; -bool ignoreLimit = true; -uint8_t analogRead_counter = 0; + +// Joint 4 +const uint8_t joint4_pulse_pin = 3; +const uint8_t joint4_dir_pin = 7; + +// Joint 5a +const uint8_t joint5a_pulse_pin = 4; +const uint8_t joint5a_dir_pin = 8; + +// Joint 5b +const uint8_t joint5b_pulse_pin = 5; +const uint8_t joint5b_dir_pin = 9; +//Color Pins +int redPin = 24; +int bluePin = 26; +int greenPin = 22; //Sabertooth Communications #include @@ -180,27 +104,25 @@ void setup() { pinMode(joint1_pulse_pin, OUTPUT); digitalWrite(joint1_enab_pin, LOW); - // Set up Joint1 - pinMode(joint5_dir_pin, OUTPUT); - //pinMode(joint5_enab_pin, OUTPUT); - pinMode(joint5_pulse_pin, OUTPUT); - //digitalWrite(joint5_enab_pin, LOW); + // Set up Joint4 + pinMode(joint4_dir_pin, OUTPUT); + pinMode(joint4_pulse_pin, OUTPUT); + digitalWrite(joint4_dir_pin, LOW); + digitalWrite(joint4_pulse_pin, LOW); + + // Set up Joint5a + pinMode(joint5a_dir_pin, OUTPUT); + pinMode(joint5a_pulse_pin, OUTPUT); + + // Set up Joint5b + pinMode(joint5b_dir_pin, OUTPUT); + pinMode(joint5b_pulse_pin, OUTPUT); - // Set up Joint1 - pinMode(joint7_dir_pin, OUTPUT); - //pinMode(joint7_enab_pin, OUTPUT); - pinMode(joint7_pulse_pin, OUTPUT); - //digitalWrite(joint7_enab_pin, LOW); - -//LED TEST CODE - pinMode(39,OUTPUT); - pinMode(41,OUTPUT); - pinMode(43,OUTPUT); - pinMode(45,OUTPUT); - pinMode(47,OUTPUT); - pinMode(49,OUTPUT); - pinMode(51,OUTPUT); - pinMode(53,OUTPUT); + + // setup the output pins for each color LED + pinMode(redPin, OUTPUT); + pinMode(bluePin, OUTPUT); + pinMode(greenPin, OUTPUT); } // This loop will be a command loop for each of the arduino processes @@ -226,8 +148,7 @@ void loop() { //Restricts the access to only when receiving network comm if (packetSize) { previousMillis = millis(); // Stores current time for check outside of loop - Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE); //reads the packet - //Serial.println(packetBuffer); + Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE); //reads the packet // parse statement for packetBuffer to Control Array // x controls buffer place, y controls current char read, // n controls placement in array @@ -250,9 +171,8 @@ void loop() { memset(charToIntArray,0,sizeof(charToIntArray)); // clear mem } } - // Loop the array and match to case and apply the values - for(int x = 0; x < 5; x++){ + for(int x = 0; x < 10; x++){ switch (x){ // drive speed case 0: @@ -277,82 +197,86 @@ void loop() { ARM.motor(2,moveMentArray[3]); break; } - case 4:{ //Joint 4 + case 4:{ //Joint 1 if(moveMentArray[4] == -1 || moveMentArray[4] == 1){ - //digitalWrite(joint1_pulse_pin,HIGH); + digitalWrite(joint1_pulse_pin,HIGH); if(moveMentArray[4] == 1){ - //digitalWrite(joint1_dir_pin,HIGH); - digitalWrite(39,HIGH); + digitalWrite(joint1_dir_pin,HIGH); + //digitalWrite(39,HIGH); } else{ - //digitalWrite(joint1_dir_pin,LOW); - digitalWrite(41,HIGH); + digitalWrite(joint1_dir_pin,LOW); + //digitalWrite(41,HIGH); } } else{ - //digitalWrite(joint1_pulse_pin,LOW); - digitalWrite(39,LOW); - digitalWrite(41,LOW); + digitalWrite(joint1_pulse_pin,LOW); + //digitalWrite(39,LOW); + //digitalWrite(41,LOW); } break; } - case 5:{ //Joint 5 + case 5:{ //Joint 4 if(moveMentArray[5] == -1 || moveMentArray[5] == 1){ - //digitalWrite(joint1_pulse_pin,HIGH); + digitalWrite(joint4_pulse_pin,HIGH); if(moveMentArray[5] == 1){ - //digitalWrite(joint1_dir_pin,HIGH); - digitalWrite(43,HIGH); + digitalWrite(joint4_dir_pin,HIGH); } else{ - //digitalWrite(joint1_dir_pin,LOW); - digitalWrite(45,HIGH); + digitalWrite(joint4_dir_pin,LOW); } } else{ - //digitalWrite(joint1_pulse_pin,LOW); - digitalWrite(43,LOW); - digitalWrite(45,LOW); + digitalWrite(joint4_pulse_pin,LOW); } break; } - case 6:{ //Joint 6 + case 6:{ //Joint 5a if(moveMentArray[6] == -1 || moveMentArray[6] == 1){ - //digitalWrite(joint1_pulse_pin,HIGH); + digitalWrite(joint5a_pulse_pin,HIGH); if(moveMentArray[6] == 1){ - //digitalWrite(joint1_dir_pin,HIGH); - digitalWrite(47,HIGH); + digitalWrite(joint5a_dir_pin,HIGH); } else{ - //digitalWrite(joint1_dir_pin,LOW); - digitalWrite(49,HIGH); + digitalWrite(joint5a_dir_pin,LOW); } } else{ - //digitalWrite(joint1_pulse_pin,LOW); - digitalWrite(47,LOW); - digitalWrite(49,LOW); + digitalWrite(joint5a_pulse_pin,LOW); } break; } - case 7:{ //Joint 7 + case 7:{ //Joint 5b if(moveMentArray[7] == -1 || moveMentArray[7] == 1){ - //digitalWrite(joint1_pulse_pin,HIGH); + digitalWrite(joint5b_pulse_pin,HIGH); if(moveMentArray[7] == 1){ - //digitalWrite(joint1_dir_pin,HIGH); - digitalWrite(51,HIGH); + digitalWrite(joint5b_dir_pin,HIGH); } else{ - //digitalWrite(joint1_dir_pin,LOW); - digitalWrite(53,HIGH); + digitalWrite(joint5b_dir_pin,LOW); } } else{ - //digitalWrite(joint1_pulse_pin,LOW); - digitalWrite(51,LOW); - digitalWrite(53,LOW); + digitalWrite(joint5b_pulse_pin,LOW); } break; } + case 9: + { + //Switch on the LEDs as per the array input number 9 + switchLEDs(moveMentArray[9]); + + + Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); + Udp.write('r'); //Change this to const array = ready + Udp.endPacket(); + + memset(packetBuffer,0,sizeof(UDP_TX_PACKET_MAX_SIZE)); + + break; + } + + //////////////////////////////////// //////////////////////////////////// @@ -365,9 +289,11 @@ void loop() { } } + + //Sends the ready command asking for next transmittion Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); - Udp.write("ready"); //Change this to const array = ready + Udp.write('r'); //Change this to const array = ready Udp.endPacket(); } //clears the buffer to ensure all new values @@ -397,4 +323,50 @@ void Step_Joint(int step1, int pulse_pin, int dir_pin, int dir ){ delay(1); } } + + + +//takes color code as input, and lights the corresponding LED +void switchLEDs(int colorCode) { + switch(colorCode) + { + case 0: + //Green + + digitalWrite(greenPin, HIGH); + + digitalWrite(bluePin, LOW); + digitalWrite(redPin, LOW); + + break; + case 1: + //Blue + + digitalWrite(bluePin, HIGH); + + digitalWrite(redPin, LOW); + digitalWrite(greenPin, LOW); + + break; + case 2: + //Purple + + digitalWrite(redPin, HIGH); + digitalWrite(bluePin, HIGH); + + digitalWrite(greenPin, LOW); + + break; + + case 3: + //Red + + digitalWrite(redPin, HIGH); + + digitalWrite(bluePin, LOW); + digitalWrite(greenPin, LOW); + + break; + } +}