Post Deleted by Community
    Post Locked by Community
    Post Migrated Away to arduino.stackexchange.com by Nick Alexeev
    Post Closed as "off-topic" by Nick Alexeev
5 reformatted
source | link
const int rLed = 3;
const int gLed = 2;
const int tempSensor = A0;
boolean lastButtonState = LOW;
long lastDebounceTime = 0;
const int BUTTON = 4;
const int buttonVal = LOW;

void setup() {

   pinMode(rLed, OUTPUT);
   pinMode(gLed, OUTPUT);
   pinMode(BUTTON, INPUT);
   Serial.begin(9600);
}

boolean debounce(boolean lastButton, long lastDebounce, int BUTTON)
{
    boolean buttonState = lastButton;
    boolean current = digitalRead(BUTTON); 

    if (current != lastButton){ //if the button state has changed
    {
        lastDebounce=millis();  //reset timer
    }

    if ((millis()-lastDebounce) > 5)  //if 50 milliseconds has passed since last bounce
    {  
        buttonState = current ;  //read value again now that bouncing is over
    } 

    return buttonState;
} 

void loop() {
{
   int temp = analogRead(tempSensor);
   float tempVolt = ((5000.0*temp)/1023.0);
   float tempRead = ((9.0*tempVolt)/50.0 - 58.0);

  if(temp > 150){
  {
     if(temp < 190) 
     {
        digitalWrite(gLed,HIGH);
        digitalWrite(rLed,LOW);
     }
 
  }
  else
  {
      digitalWrite(rLed,HIGH);
      digitalWrite(gLed,LOW);
  }

  //Debounce Function
 
  boolean buttonVal = debounce(lastButtonState, lastDebounceTime, BUTTON); 

  if (buttonVal == HIGH && lastButtonState == LOW)
  { 
 
      Serial.print("F =");
      Serial.println(tempRead);
      Serial.print("D =");
      Serial.println(temp);
      Serial.print("mV =");
      Serial.println(tempVolt);
      Serial.println();
      delay(10000);
  }
  
  lastButtonState = buttonVal;
 

}
const int rLed = 3;
const int gLed = 2;
const int tempSensor = A0;
boolean lastButtonState = LOW;
long lastDebounceTime = 0;
const int BUTTON = 4;
const int buttonVal = LOW;

void setup() {

pinMode(rLed, OUTPUT);
pinMode(gLed, OUTPUT);
pinMode(BUTTON, INPUT);
Serial.begin(9600);
}

boolean debounce(boolean lastButton, long lastDebounce, int BUTTON)
{
  boolean buttonState = lastButton;
  boolean current = digitalRead(BUTTON);
  if (current != lastButton){ //if the button state has changed
    lastDebounce=millis();  //reset timer
    }

  if ((millis()-lastDebounce) > 5)  //if 50 milliseconds has passed since last bounce
  {  
    buttonState = current ;  //read value again now that bouncing is over
    }
  return buttonState;
} 

void loop() {

int temp = analogRead(tempSensor);
float tempVolt = ((5000.0*temp)/1023.0);
float tempRead = ((9.0*tempVolt)/50.0 - 58.0);

if(temp > 150){

  if(temp < 190){
  digitalWrite(gLed,HIGH);
  digitalWrite(rLed,LOW);
  }
 
  }
else{
  digitalWrite(rLed,HIGH);
  digitalWrite(gLed,LOW);
  }

//Debounce Function
 
  boolean buttonVal = debounce(lastButtonState, lastDebounceTime, BUTTON);
  if (buttonVal == HIGH && lastButtonState == LOW){ 
 
  Serial.print("F =");
  Serial.println(tempRead);
  Serial.print("D =");
  Serial.println(temp);
  Serial.print("mV =");
  Serial.println(tempVolt);
  Serial.println();
  delay(10000);
  }
   lastButtonState = buttonVal;
 

}
const int rLed = 3;
const int gLed = 2;
const int tempSensor = A0;
boolean lastButtonState = LOW;
long lastDebounceTime = 0;
const int BUTTON = 4;
const int buttonVal = LOW;

void setup() {

   pinMode(rLed, OUTPUT);
   pinMode(gLed, OUTPUT);
   pinMode(BUTTON, INPUT);
   Serial.begin(9600);
}

boolean debounce(boolean lastButton, long lastDebounce, int BUTTON)
{
    boolean buttonState = lastButton;
    boolean current = digitalRead(BUTTON); 

    if (current != lastButton) //if the button state has changed
    {
        lastDebounce=millis();  //reset timer
    }

    if ((millis()-lastDebounce) > 5)  //if 50 milliseconds has passed since last bounce
    {  
        buttonState = current ;  //read value again now that bouncing is over
    } 

    return buttonState;
} 

void loop()
{
   int temp = analogRead(tempSensor);
   float tempVolt = ((5000.0*temp)/1023.0);
   float tempRead = ((9.0*tempVolt)/50.0 - 58.0);

  if(temp > 150)
  {
     if(temp < 190) 
     {
        digitalWrite(gLed,HIGH);
        digitalWrite(rLed,LOW);
     }
  }
  else
  {
      digitalWrite(rLed,HIGH);
      digitalWrite(gLed,LOW);
  }

  //Debounce Function
  boolean buttonVal = debounce(lastButtonState, lastDebounceTime, BUTTON); 

  if (buttonVal == HIGH && lastButtonState == LOW)
  { 
      Serial.print("F =");
      Serial.println(tempRead);
      Serial.print("D =");
      Serial.println(temp);
      Serial.print("mV =");
      Serial.println(tempVolt);
      Serial.println();
      delay(10000);
  }
 
  lastButtonState = buttonVal;

}
4 Fixed code.
source | link

A little while ago I made a function to debounce a button and return its value. The void loop then read the button to know whether or not to blink the LED. It worked perfectly. I am now using this exact same function to Serial.println when button is pressed, but this isn't working... the state of the button keeps reading zero no matter what. Any ideas? const int rLed = 3; const int gLed = 2; const int tempSensor = A0; boolean lastButtonState = LOW; long lastDebounceTime = 0; const int BUTTON = 4; const int buttonVal = LOW;

const int rLed = 3;
const int gLed = 2;
const int tempSensor = A0;
boolean lastButtonState = LOW;
long lastDebounceTime = 0;
const int BUTTON = 4;
const int buttonVal = LOW;

void setup() {

pinMode(rLed, OUTPUT);
pinMode(gLed, OUTPUT);
pinMode(BUTTON, INPUT);
Serial.begin(9600);
}

boolean debounce(boolean lastButton, long lastDebounce, int BUTTON)
{
  boolean buttonState = lastButton;
  boolean current = digitalRead(BUTTON);
  if (current != lastButton){ //if the button state has changed
    lastDebounce=millis();  //reset timer
    }

  if ((millis()-lastDebounce) > 5)  //if 50 milliseconds has passed since last bounce
  {  
    buttonState = current ;  //read value again now that bouncing is over
    }
  return buttonState;
} 

void loop() {

int temp = analogRead(tempSensor);
float tempVolt = ((5000.0*temp)/1023.0);
float tempRead = ((9.0*tempVolt)/50.0 - 58.0);

if(temp > 150){

  if(temp < 190){
  digitalWrite(gLed,HIGH);
  digitalWrite(rLed,LOW);
  }

  }
else{
  digitalWrite(rLed,HIGH);
  digitalWrite(gLed,LOW);
  }

//Debounce Function

  boolean buttonVal = debounce(lastButtonState, lastDebounceTime, BUTTON);
  if (buttonVal == HIGH && lastButtonState == LOW){ 

  Serial.print("F =");
  Serial.println(tempRead);
  Serial.print("D =");
  Serial.println(temp);
  Serial.print("mV =");
  Serial.println(tempVolt);
  Serial.println();
  delay(10000);
  }
   lastButtonState = buttonVal;


}

A little while ago I made a function to debounce a button and return its value. The void loop then read the button to know whether or not to blink the LED. It worked perfectly. I am now using this exact same function to Serial.println when button is pressed, but this isn't working... the state of the button keeps reading zero no matter what. Any ideas? const int rLed = 3; const int gLed = 2; const int tempSensor = A0; boolean lastButtonState = LOW; long lastDebounceTime = 0; const int BUTTON = 4; const int buttonVal = LOW;

void setup() {

pinMode(rLed, OUTPUT);
pinMode(gLed, OUTPUT);
pinMode(BUTTON, INPUT);
Serial.begin(9600);
}

boolean debounce(boolean lastButton, long lastDebounce, int BUTTON)
{
  boolean buttonState = lastButton;
  boolean current = digitalRead(BUTTON);
  if (current != lastButton){ //if the button state has changed
    lastDebounce=millis();  //reset timer
    }

  if ((millis()-lastDebounce) > 5)  //if 50 milliseconds has passed since last bounce
  {  
    buttonState = current ;  //read value again now that bouncing is over
    }
  return buttonState;
} 

void loop() {

int temp = analogRead(tempSensor);
float tempVolt = ((5000.0*temp)/1023.0);
float tempRead = ((9.0*tempVolt)/50.0 - 58.0);

if(temp > 150){

  if(temp < 190){
  digitalWrite(gLed,HIGH);
  digitalWrite(rLed,LOW);
  }

  }
else{
  digitalWrite(rLed,HIGH);
  digitalWrite(gLed,LOW);
  }

//Debounce Function

  boolean buttonVal = debounce(lastButtonState, lastDebounceTime, BUTTON);
  if (buttonVal == HIGH && lastButtonState == LOW){ 

  Serial.print("F =");
  Serial.println(tempRead);
  Serial.print("D =");
  Serial.println(temp);
  Serial.print("mV =");
  Serial.println(tempVolt);
  Serial.println();
  delay(10000);
  }
   lastButtonState = buttonVal;


}

A little while ago I made a function to debounce a button and return its value. The void loop then read the button to know whether or not to blink the LED. It worked perfectly. I am now using this exact same function to Serial.println when button is pressed, but this isn't working... the state of the button keeps reading zero no matter what. Any ideas?

const int rLed = 3;
const int gLed = 2;
const int tempSensor = A0;
boolean lastButtonState = LOW;
long lastDebounceTime = 0;
const int BUTTON = 4;
const int buttonVal = LOW;

void setup() {

pinMode(rLed, OUTPUT);
pinMode(gLed, OUTPUT);
pinMode(BUTTON, INPUT);
Serial.begin(9600);
}

boolean debounce(boolean lastButton, long lastDebounce, int BUTTON)
{
  boolean buttonState = lastButton;
  boolean current = digitalRead(BUTTON);
  if (current != lastButton){ //if the button state has changed
    lastDebounce=millis();  //reset timer
    }

  if ((millis()-lastDebounce) > 5)  //if 50 milliseconds has passed since last bounce
  {  
    buttonState = current ;  //read value again now that bouncing is over
    }
  return buttonState;
} 

void loop() {

int temp = analogRead(tempSensor);
float tempVolt = ((5000.0*temp)/1023.0);
float tempRead = ((9.0*tempVolt)/50.0 - 58.0);

if(temp > 150){

  if(temp < 190){
  digitalWrite(gLed,HIGH);
  digitalWrite(rLed,LOW);
  }

  }
else{
  digitalWrite(rLed,HIGH);
  digitalWrite(gLed,LOW);
  }

//Debounce Function

  boolean buttonVal = debounce(lastButtonState, lastDebounceTime, BUTTON);
  if (buttonVal == HIGH && lastButtonState == LOW){ 

  Serial.print("F =");
  Serial.println(tempRead);
  Serial.print("D =");
  Serial.println(temp);
  Serial.print("mV =");
  Serial.println(tempVolt);
  Serial.println();
  delay(10000);
  }
   lastButtonState = buttonVal;


}
3 I originally showed a simplified version of my program, but now I'm showing the whole program.
source | link

A little while ago I made a function to debounce a button and return its value. The void loop then read the button to know whether or not to blink the LED. It worked perfectly. I am now using this exact same function to Serial.println when button is pressed, but this isn't working... the state of the button keeps reading zero no matter what. Any ideas? const int rLed = 3; const int gLed = 2; const int tempSensor = A0; boolean lastButtonState = LOW; long lastDebounceTime = 0; const int BUTTON = 4; const int buttonVal = LOW;

boolean lastButton = LOW;
long lastDebounce = 0;
const int BUTTON = 4;
const int buttonVal = LOW;

void setup() {
  // put your setup code here
pinMode(rLed, to runOUTPUT);
pinMode(gLed, once:OUTPUT);
pinMode(BUTTON, INPUT);
Serial.begin(9600);
}

boolean debounce(boolean lastButton, long lastDebounce, int BUTTON)
{
  boolean buttonState;buttonState = lastButton;
  boolean current = digitalRead(BUTTON);
  if (current != lastButton){ //if the button state has changed
    lastDebounce=millis();  //reset timer
    }

  if ((millis()-lastDebounce) > 505)  //if 50 milliseconds has passed since last bounce
  {  
    buttonState = current ;  //read value again now that bouncing is over
    }
  return buttonState;
} 

void loop() { 

int temp = analogRead(tempSensor);
float tempVolt = ((5000.0*temp)/1023.0);
float tempRead = ((9.0*tempVolt)/50.0 put- your58.0);

if(temp main> code150){

 here if(temp < 190){
  digitalWrite(gLed,HIGH);
 to rundigitalWrite(rLed,LOW);
 repeatedly: }

  }
else{
  digitalWrite(rLed,HIGH);
  digitalWrite(gLed,LOW);
  }

//Debounce Function

  boolean buttonVal = debounce(lastButtonlastButtonState, lastDebouncelastDebounceTime, BUTTON);
  lastButtonif =(buttonVal buttonVal;== HIGH && lastButtonState == LOW){ 

  Serial.print("F =");
  Serial.println(buttonValtempRead);
  Serial.print("D =");
  Serial.println(temp);
  Serial.print("mV =");
  Serial.println(tempVolt);
  Serial.println();
  delay(50010000);
  }
   lastButtonState = buttonVal;


}

A little while ago I made a function to debounce a button and return its value. The void loop then read the button to know whether or not to blink the LED. It worked perfectly. I am now using this exact same function to Serial.println when button is pressed, but this isn't working... the state of the button keeps reading zero no matter what. Any ideas?

boolean lastButton = LOW;
long lastDebounce = 0;
const int BUTTON = 4;
const int buttonVal = LOW;

void setup() {
  // put your setup code here, to run once:
pinMode(BUTTON, INPUT);
}

boolean debounce(boolean lastButton, long lastDebounce, int BUTTON)
{
  boolean buttonState;
  boolean current = digitalRead(BUTTON);
  if (current != lastButton){ //if the button state has changed
  lastDebounce=millis();  //reset timer
}

  if ((millis()-lastDebounce) > 50)  //if 50 milliseconds has passed since last bounce
  {  
    buttonState = current ;  //read value again now that bouncing is over
    }
  return buttonState;
} 

void loop() {
  // put your main code here, to run repeatedly:
  boolean buttonVal = debounce(lastButton, lastDebounce, BUTTON);
  lastButton = buttonVal;
  Serial.println(buttonVal);
  delay(500);
}

A little while ago I made a function to debounce a button and return its value. The void loop then read the button to know whether or not to blink the LED. It worked perfectly. I am now using this exact same function to Serial.println when button is pressed, but this isn't working... the state of the button keeps reading zero no matter what. Any ideas? const int rLed = 3; const int gLed = 2; const int tempSensor = A0; boolean lastButtonState = LOW; long lastDebounceTime = 0; const int BUTTON = 4; const int buttonVal = LOW;

void setup() {

pinMode(rLed, OUTPUT);
pinMode(gLed, OUTPUT);
pinMode(BUTTON, INPUT);
Serial.begin(9600);
}

boolean debounce(boolean lastButton, long lastDebounce, int BUTTON)
{
  boolean buttonState = lastButton;
  boolean current = digitalRead(BUTTON);
  if (current != lastButton){ //if the button state has changed
    lastDebounce=millis();  //reset timer
    }

  if ((millis()-lastDebounce) > 5)  //if 50 milliseconds has passed since last bounce
  {  
    buttonState = current ;  //read value again now that bouncing is over
    }
  return buttonState;
} 

void loop() { 

int temp = analogRead(tempSensor);
float tempVolt = ((5000.0*temp)/1023.0);
float tempRead = ((9.0*tempVolt)/50.0 - 58.0);

if(temp > 150){

  if(temp < 190){
  digitalWrite(gLed,HIGH);
  digitalWrite(rLed,LOW);
  }

  }
else{
  digitalWrite(rLed,HIGH);
  digitalWrite(gLed,LOW);
  }

//Debounce Function

  boolean buttonVal = debounce(lastButtonState, lastDebounceTime, BUTTON);
  if (buttonVal == HIGH && lastButtonState == LOW){ 

  Serial.print("F =");
  Serial.println(tempRead);
  Serial.print("D =");
  Serial.println(temp);
  Serial.print("mV =");
  Serial.println(tempVolt);
  Serial.println();
  delay(10000);
  }
   lastButtonState = buttonVal;


}
2 added 1 character in body
source | link
1
source | link