//YWROBOT //Compatible with the Arduino IDE 1.0 //Library version:1.1 #include #include #include #include #include "Flavors.cpp" #include "constants.cpp" SoftwareSerial mySerial(2,3); //RX on pin 2, TX on pin 3 // constants won't change. They're used here to set pin numbers: // PLEASE SET DIGITAL PIN VALUE const int buttonPin_FORWARD = 9; // set this to match the arduino pin the FORWARD button is connected to // PLEASE SET DIGITAL PIN VALUE const int buttonPin_BACK = 8; // set this to match the arduino pin the BACK button is connected to // PLEASE SET DIGITAL PIN VALUE const int buttonPin_SELECT = 10; // set this to match the arduino pin the SELECT button is connected to // PLEASE SET TO ANALOGUE PIN VALUE const int ledPin = 0; // pin for neopixel data // button status value init int buttonState_FORWARD = 0; // variable for reading the FORWARD pushbutton status int buttonState_BACK = 0; // variable for reading the BACK pushbutton status int buttonState_SELECT = 0; // variable for reading the SELECT pushbutton status int buttonPause = 0; // when this is 1, buttons inputs will not be read int rotcount = 0; //this is the variable to just keep rotating for the kicker motor // string constants const String WelcomeText = "Welcome "; const String OrderPrompt = "What would you like? "; const String controlsPrompt = "<- previous , next ->"; const String thanksText = "Thank You"; // How many NeoPixels are attached to the Arduino? #define NUMPIXELS 5 // Popular NeoPixel ring size // When setting up the NeoPixel library, we tell it how many pixels, // and which pin to use to send signals. Note that for older NeoPixel // strips you might need to change the third parameter -- see the // strandtest example for more information on possible values. Adafruit_NeoPixel pixels(NUMPIXELS, ledPin, NEO_GRB + NEO_KHZ800); // set the LCD address to 0x27 for a 16 chars and 2 line display LiquidCrystal_I2C lcd(0x27,20,4); // creates empty array for holding flavor values int flavorCount = 10; Flavor* flavorSelection = new Flavor[flavorCount]; // variables for currently selceted flavor int menuIndex = 0; Flavor currentFlavor; void setup() { // initialize flavor list and start cutrrent selceted flavor at first flavor in list populateFlavorList(); currentFlavor = flavorSelection[0]; Serial.begin(115200); //start serial comm with computer at baud rate 9600 baud. mySerial.begin(115200); //start serial comm with computer at baud rate 115200 baud. lcd.init(); // initialize the lcd lcd.init(); // Print a message to the LCD. lcd.backlight(); // for first 3 seconds after powering on, tell the user welcome lcd.print(WelcomeText); delay(3000); // update screen to display the name of the currently selected flavor lcd.clear(); lcd.print(currentFlavor.getName()); //button init pinMode(buttonPin_FORWARD, INPUT); pinMode(buttonPin_BACK, INPUT); pinMode(buttonPin_SELECT, INPUT); } void loop() { // read the states of the pushbutton values: buttonState_FORWARD = digitalRead(buttonPin_FORWARD); buttonState_BACK = digitalRead(buttonPin_BACK); buttonState_SELECT = digitalRead(buttonPin_SELECT); // if buttonPause is active, do not regard button inputs if (buttonPause == 1){ delay(500); } else { // select button status takes priority over all other button values if (buttonState_SELECT == HIGH){ select(); } // if select button is not being pressed, check other buttons else{ // if forward and back buttons are pressed at same time, wait and do nothing if( (buttonState_FORWARD == HIGH) and (buttonState_BACK == HIGH) ){ delay(100); } // if forward button is pressed, cycle forward else if(buttonState_FORWARD == HIGH){ cycleForward(); delay(1000); } // if back button is pressed, cycle back else if(buttonState_BACK == HIGH){ cycleBack(); delay(1000); } } } delay(100); } // updates LCD screen to display the name of // the currently selceted flavor void updateSelectedFlavor(){ currentFlavor = flavorSelection[menuIndex]; lcd.clear(); lcd.print(currentFlavor.getName()); } // executed on Forward button pressed // selects next flavor in the list (jumps to start if out of bounds) // updates screen and neopixels void cycleForward(){ menuIndex++; if(menuIndex >= flavorCount){ menuIndex = 0; } updateSelectedFlavor(); cycleColor(); } // executed on Back button pressed // selects previous flavor in the list (jumps to end if out of bounds) // updates screen and neopixels void cycleBack(){ menuIndex--; if(menuIndex < 0){ menuIndex = flavorCount-1; } updateSelectedFlavor(); cycleColor(); } // updates the color of the neopixels strip to reflect // the color of the currently selected flavor void cycleColor(){ for(int i=0;i