Home project: Tea maker

Hi,

I'm new to this and i need some help. Given the nature of my project automatic tea maker, inputs are needed before we start brewing the tea different temperature and different time. Using push buttons and LED to help me achieve this. One push button to control 6 LED's: once the first one lights up you push again it closes and the second one lights up and so on. (Then when the code would assign the info to the heater for the given inputs )future work*.
Here is my code so far, I don't know what to do with the loop part?

On and off switch program
*/

// global variable
int switchPin = 2;
int ledPin1 = 13;
int ledPin2 = 12;
int ledPin3 = 11;
boolean lastButton=LOW;
boolean ledOn =false;
boolean currentButton=LOW;

void setup()
{
pinMode(switchPin, INPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2,OUTPUT);
pinMode(ledPin3,OUTPUT);
}
boolean debounce(boolean last)
{

// set value of current state
boolean current = digitalRead(switchPin);
if (last!=current)
{
delay(5);
current = digitalRead(switchPin);
}
return current;
}

void loop()
{
currentButton = debounce(lastButton);
if (lastButton == LOW && currentButton ==HIGH )
{
ledOn= !ledOn;

}
lastButton = currentButton;
digitalWrite(ledPin1, ledOn);

if(lastButton == LOW && currentButton ==HIGH )
{
ledOn=!ledOn;
}
lastButton=currentButton;
digitalWrite(ledPin2,ledOn);
}

Thanks

Philippe, could you put your code in the code /code brackets, use the # button, it makes it easier for us to read your code.

Take a peek at this thread, it might help you allot:

I guess u have one item missing;-

Tea leaf auto feeder, for my understand, u need first heat water from room temperature to preset temperature ( varying base on diff tea) then auto feed the Tea leaf.

Thanks for the reply guys I figured out what I need. In the following script I got the LED to work with the push button using a crude code as shown below.
{
switchstate1 = digitalRead(switchPin1); // read the input pin
if (switchstate1==1)
}
But now I want to implement a debounce code in the void setup part and everything in green is what I added. But the syntax is wrong any feed back is appreciated.

The temperature part will be incorporated afterwards when I tying the thermocouple to read the voltages and the heater will simply be on and off, so no need for a controller.

/*
Temp&Time push button inputs
*/

boolean lastbutton1=LOW;
boolean lastbutton2=LOW;
boolean ledOn1=false;
boolean ledOn2=false;
boolean currentButton1=LOW;
boolean currentButton2=LOW;

// global variable
int switchPin1 = 1;
int ledPin1 = 13;
int ledPin2 = 12;
int ledPin3 = 11;
int ledPin4 = 10;
int ledPin5 = 9;
int ledPin6 = 8;
int switchstate1;
int i=0;
int j=0;
// time
int switchPin2 = 14;
int ledPin7 = 7;
int ledPin8 = 6;
int ledPin9 = 5;
int ledPin10 = 4;
int ledPin11= 3;
int ledPin12= 2;
int switchstate2;
int r=0;
int t=0;
void setup()
{
pinMode(switchPin1, INPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);
pinMode(switchPin2, INPUT);
pinMode(ledPin7, OUTPUT);
pinMode(ledPin8, OUTPUT);
pinMode(ledPin9, OUTPUT);
pinMode(ledPin10, OUTPUT);
pinMode(ledPin11, OUTPUT);
pinMode(ledPin12, OUTPUT);

}

boolean debounce1(boolean last1);

boolean current1=(digitalRead(switchPin1));
if (last1 != current1)
{
delay(5);
current1=digitalRead(switchPin1);
}
return current1;
{
boolean debounce2(boolean last2);

boolean current2=digitalRead(switchPin2);
if (last2 != current2);
{
delay(5);
current2=digitalRead(switchPin2);
}
return current2;
}
void loop()
{
currentButton1=debounce1(lastButton1);
if(lastButton1==LOW && currentButton1==HIGH)
{
ledOn1=!ledOn1;
{
lastButton1=currentButton1;
}
{
j=j+1;
}
if (j==1)
{
i=i+1;
}
if (i>6)
{
i=0;
digitalWrite(ledPin1,LOW);
digitalWrite(ledPin2,LOW);
digitalWrite(ledPin3,LOW);
digitalWrite(ledPin4,LOW);
digitalWrite(ledPin5,LOW);
digitalWrite(ledPin6,LOW);
}
if (i==1)
{
digitalWrite(ledPin1, HIGH);
}
else if (i==2)
{
digitalWrite(ledPin1,LOW);
digitalWrite(ledPin2,HIGH);

//temp=temp_setpoint1;
}
else if (i==3)
{
digitalWrite(ledPin1,LOW);
digitalWrite(ledPin2,LOW);
digitalWrite(ledPin3,HIGH);
}
else if (i==4)
{
digitalWrite(ledPin1,LOW);
digitalWrite(ledPin2,LOW);
digitalWrite(ledPin3,LOW);
digitalWrite(ledPin4,HIGH);
}
else if (i==5)
{
digitalWrite(ledPin1,LOW);
digitalWrite(ledPin2,LOW);
digitalWrite(ledPin3,LOW);
digitalWrite(ledPin4,LOW);
digitalWrite(ledPin5,HIGH);
}
else if (i==6)
{
digitalWrite(ledPin1,LOW);
digitalWrite(ledPin2,LOW);
digitalWrite(ledPin3,LOW);
digitalWrite(ledPin4,LOW);
digitalWrite(ledPin5,LOW);
digitalWrite(ledPin6,HIGH);
}
currentButton2=debounce2(lastButton2);
if(lastButton2==LOW && currentButton2==HIGH)
{
ledOn2=!ledOn2;
{
lastButton2=currentButton2;
}
{
t=t+1;
}
if (t==1)
{
r=r+1;
}
if (r>6)
{
r=0;
digitalWrite(ledPin7,LOW);
digitalWrite(ledPin8,LOW);
digitalWrite(ledPin9,LOW);
digitalWrite(ledPin10,LOW);
digitalWrite(ledPin11,LOW);
digitalWrite(ledPin12,LOW);
}
if (r==1)
{
digitalWrite(ledPin7, HIGH);
}
else if (r==2)
{
digitalWrite(ledPin7,LOW);
digitalWrite(ledPin8,HIGH);

//temp=temp_setpoint1
}
else if (r==3)
{
digitalWrite(ledPin7,LOW);
digitalWrite(ledPin8,LOW);
digitalWrite(ledPin9,HIGH);
}
else if (r==4)
{
digitalWrite(ledPin7,LOW);
digitalWrite(ledPin8,LOW);
digitalWrite(ledPin9,LOW);
digitalWrite(ledPin10,HIGH);
}
else if (r==5)
{
digitalWrite(ledPin7,LOW);
digitalWrite(ledPin8,LOW);
digitalWrite(ledPin9,LOW);
digitalWrite(ledPin10,LOW);
digitalWrite(ledPin11,HIGH);
}
else if (r==6)
{
digitalWrite(ledPin7,LOW);
digitalWrite(ledPin8,LOW);
digitalWrite(ledPin9,LOW);
digitalWrite(ledPin10,LOW);
digitalWrite(ledPin11,LOW);
digitalWrite(ledPin12,HIGH);
}
}

I took the debounce code from this video if this helps

Thanks

Cleaned up syntax and compiles now: still need functional lookover

/*
Temp&Time push button inputs
*/

boolean lastbutton1=LOW;
boolean lastbutton2=LOW;
boolean ledOn1=false;
boolean ledOn2=false;
boolean currentButton1=LOW;
boolean currentButton2=LOW;

// global variable
int switchPin1 = 1;
int ledPin1 = 13;
int ledPin2 = 12;
int ledPin3 = 11;
int ledPin4 = 10;
int ledPin5 = 9;
int ledPin6 = 8;
int switchstate1;
int i=0;
int j=0;
// time
int switchPin2 = 14;
int ledPin7 = 7;
int ledPin8 = 6;
int ledPin9 = 5;
int ledPin10 = 4;
int ledPin11= 3;
int ledPin12= 2;
int switchstate2;
int r=0;
int t=0;

//----------------------------------------------------------------
void setup()
{ pinMode(switchPin1, INPUT);
  pinMode(ledPin1 , OUTPUT);
  pinMode(ledPin2 , OUTPUT);
  pinMode(ledPin3 , OUTPUT);
  pinMode(ledPin4 , OUTPUT);
  pinMode(ledPin5 , OUTPUT);
  pinMode(ledPin6 , OUTPUT);
  pinMode(switchPin2, INPUT);
  pinMode(ledPin7 , OUTPUT);
  pinMode(ledPin8 , OUTPUT);
  pinMode(ledPin9 , OUTPUT);
  pinMode(ledPin10, OUTPUT);
  pinMode(ledPin11, OUTPUT);
  pinMode(ledPin12, OUTPUT);
}//setup
//----------------------------------------------------------------
boolean debounce1(boolean last1)
{ boolean current1 = digitalRead(switchPin1);
  if (last1 != current1)
  { delay(5);
    current1 = digitalRead(switchPin1);
  }
  return current1;
}
//----------------------------------------------------------------
boolean debounce2(boolean last2)
{ boolean current2 = digitalRead(switchPin2);
  if (last2 != current2);
  { delay(5);
    current2 = digitalRead(switchPin2);
  }
  return current2;
}
//----------------------------------------------------------------
void loop()
{
  currentButton1 = debounce1(lastbutton1);
  
  if(lastbutton1==LOW && currentButton1==HIGH)
  { ledOn1=!ledOn1;
    lastbutton1=currentButton1;
    j=j+1;
  }

  if (j==1) i=i+1;

  if      (i==1)
  { digitalWrite(ledPin1, HIGH);
  }
  else if (i==2)
  { digitalWrite(ledPin1,LOW);
    digitalWrite(ledPin2,HIGH);
    //temp=temp_setpoint1;
  }
  else if (i==3)
  { digitalWrite(ledPin1,LOW);
    digitalWrite(ledPin2,LOW);
    digitalWrite(ledPin3,HIGH);
  }
  else if (i==4)
  { digitalWrite(ledPin1,LOW);
    digitalWrite(ledPin2,LOW);
    digitalWrite(ledPin3,LOW);
    digitalWrite(ledPin4,HIGH);
  }
  else if (i==5)
  { digitalWrite(ledPin1,LOW);
    digitalWrite(ledPin2,LOW);
    digitalWrite(ledPin3,LOW);
    digitalWrite(ledPin4,LOW);
    digitalWrite(ledPin5,HIGH);
  }
  else if (i==6)
  { digitalWrite(ledPin1,LOW);
    digitalWrite(ledPin2,LOW);
    digitalWrite(ledPin3,LOW);
    digitalWrite(ledPin4,LOW);
    digitalWrite(ledPin5,LOW);
    digitalWrite(ledPin6,HIGH);
  }
  if (i>6)
  { i=0;
    digitalWrite(ledPin1,LOW);
    digitalWrite(ledPin2,LOW);
    digitalWrite(ledPin3,LOW);
    digitalWrite(ledPin4,LOW);
    digitalWrite(ledPin5,LOW);
    digitalWrite(ledPin6,LOW);
  }

  currentButton2 = debounce2(lastbutton2);

  if(lastbutton2==LOW && currentButton2==HIGH)
  { ledOn2=!ledOn2;
    lastbutton2=currentButton2;
    t=t+1;
  }

  if (t==1) r=r+1;

  if      (r==1)
  { digitalWrite(ledPin7, HIGH);
  }
  else if (r==2)
  { digitalWrite(ledPin7,LOW);
    digitalWrite(ledPin8,HIGH);
  
  //temp=temp_setpoint1
  }
  else if (r==3)
  { digitalWrite(ledPin7,LOW);
    digitalWrite(ledPin8,LOW);
    digitalWrite(ledPin9,HIGH);
  }
  else if (r==4)
  {
    digitalWrite(ledPin7,LOW);
    digitalWrite(ledPin8,LOW);
    digitalWrite(ledPin9,LOW);
    digitalWrite(ledPin10,HIGH);
  }
  else if (r==5)
  {
    digitalWrite(ledPin7,LOW);
    digitalWrite(ledPin8,LOW);
    digitalWrite(ledPin9,LOW);
    digitalWrite(ledPin10,LOW);
    digitalWrite(ledPin11,HIGH);
  }
  else if (r==6)
  {
    digitalWrite(ledPin7,LOW);
    digitalWrite(ledPin8,LOW);
    digitalWrite(ledPin9,LOW);
    digitalWrite(ledPin10,LOW);
    digitalWrite(ledPin11,LOW);
    digitalWrite(ledPin12,HIGH);
  }
  if (r>6)
  { r=0;
    digitalWrite(ledPin7,LOW);
    digitalWrite(ledPin8,LOW);
    digitalWrite(ledPin9,LOW);
    digitalWrite(ledPin10,LOW);
    digitalWrite(ledPin11,LOW);
    digitalWrite(ledPin12,LOW);
  }

}//loop

main problems were :

  • the functions debounce1(), debounce2() were not formatted as functions
  • some typo's with variable names