Hey guys!
Im working on an arduino project for school. The gist of it is that it's a marshmallow roaster controlled via an IR remote. I used multiple switch cases to declare the variables i use for calculating the amount of rotations my stepper motor has to make but for some reason any button I press after the first will not overwrite the input Value no matter what i do. This is my first arduino project what am i doing wrong?
thank you in advance
#include <LiquidCrystal.h>
#include "Stepper.h"
#include "IRremote.h"
/*----- Variables, Pins -----*/
#define STEPS 32 // Number of steps per revolution of Internal shaft
int Steps2Take; // 2048 = 1 Revolution
int receiver = 3; // Signal Pin of IR receiver to Arduino Digital Pin 3
/*-----( Declare objects )-----*/
// Setup of proper sequencing for Motor Driver Pins
// In1, In2, In3, In4 in the sequence 1-3-2-4
LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7)
Stepper small_stepper(STEPS, 8, 10, 9, 11);
IRrecv irrecv(receiver); // create instance of 'irrecv'
decode_results results; // create instance of 'decode_results'
void setup()
{
lcd.begin(16,2);
irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
int format = 0;
int cooked = 0;
int crisp = 0;
lcd.setCursor(0,0);
lcd.print("Welcome, Size?");
lcd.setCursor(2,1);
lcd.print("1:S 2:M 3:L ? ");
if (irrecv.decode(&results)) // have we received an IR signal?
{
switch(results.value)
{
case 0xFF30CF: // 1 button pressed
format = 100;
lcd.clear();
delay(300);
lcd.print("Small");
lcd.setCursor(0,1);
lcd.print("Marshamllow");
lcd.setCursor(0,0);
delay(1000);
lcd.clear();
break;
case 0xFF18E7: // 2 button pressed
format = 150;
lcd.clear();
delay(300);
lcd.print("Medium");
lcd.setCursor(0,1);
lcd.print("Marshamllow");
lcd.setCursor(0,0);
delay(1000);
lcd.clear();
break;
case 0x6182021B: // 3 button pressed
format = 200;
lcd.clear();
delay(300);
lcd.print("Big boy");
lcd.setCursor(0,1);
lcd.print("Marshamllow");
lcd.setCursor(0,0);
delay(1000);
lcd.clear();
break;
}
irrecv.resume(); // receive the next value
lcd.print("Crisp?");
lcd.setCursor(0,1);
lcd.print("1:- 2:+ 3:++");
delay(5000);
lcd.clear();
/*---------CASE2---------*/
switch(results.value){
case 0xFF30CF: // 1 button pressed
crisp = 600;
lcd.clear();
delay(300);
lcd.print("Niet zo");
lcd.setCursor(0,1);
lcd.print("Crispy");
lcd.setCursor(0,0);
delay(1000);
lcd.clear();
break;
case 0xFF18E7: // 2 button pressed
crisp = 400;
lcd.clear();
delay(300);
lcd.print("Redelijk");
lcd.setCursor(0,1);
lcd.print("Crispy");
lcd.setCursor(0,0);
delay(1000);
lcd.clear();
break;
case 0x6182021B: // 3 button pressed
crisp = 200;
lcd.clear();
delay(300);
lcd.print("Maximum");
lcd.setCursor(0,1);
lcd.print("Crisp");
lcd.setCursor(0,0);
delay(1000);
lcd.clear();
break;
}
irrecv.resume(); // receive the next value
lcd.print("Doorbakken?");
lcd.setCursor(0,1);
lcd.print("1:- 2:+ 3:++");
delay(5000);
lcd.clear();
/*---------CASE3---------*/
switch(results.value){
case 0xFF30CF: // 1 button pressed
cooked = 120;
lcd.clear();
delay(300);
lcd.print("Bleu");
delay(1000);
lcd.clear();
break;
case 0xFF18E7: // 2 button pressed
cooked = 140;
lcd.clear();
delay(300);
lcd.print("A Point");
delay(1000);
lcd.clear();
break;
case 0x6182021B: // 3 button pressed
cooked = 120;
lcd.clear();
delay(300);
lcd.print("Bien Cuit");
delay(1000);
lcd.clear();
break;
}
lcd.print("Preparing...");
small_stepper.setSpeed(crisp); //Max seems to be 700
Steps2Take = (cooked*format); // Rotate CW
small_stepper.step(Steps2Take);
lcd.print("Ready");
delay(2000);
irrecv.resume(); // receive the next value
lcd.clear();
}
}
/* --end main loop -- */
/* small_stepper.setSpeed(500); //Max seems to be 700
Steps2Take = 2048; // Rotate CW
small_stepper.step(Steps2Take);
delay(2000);
lcd.clear();
break; */
backup.ino (6.01 KB)