hi there,
i am kind a newbie to this world and i was emulating serial communication on arduino using virtual terminal on the proteus. i just wrote a code below to send appropiate string massage to the terminal, nut when i press the input appears, arduino sends multiple massage (duplicate) on the terminal instead of just one massage per decision. i don’t know whats wrong can some one help me out
// delaration of the analogue input
float inputSignalRoom1 = 0;
float inputSignalRoom2 = 0;
float normValue1 = 0;
int button1 = A0;
int R1Green = 5;
int R1Red = 6;
boolean lastGreenStatus = LOW;
boolean lastRedStatus = LOW;
long timeR = 0;
long timeG = 0;
long timeD = 0;
// main program set up
void setup ()
{
Serial.begin(9600);
pinMode(R1Green, OUTPUT);
pinMode(R1Red, OUTPUT);
}
// main program
void loop()
{
// get value of input of the room1
inputSignalRoom1 = analogRead(button1);
normValue1 = (inputSignalRoom1/204.6)*200;
if (normValue1>= 241 && normValue1 < 347 && lastRedStatus == LOW)
{
digitalWrite(R1Green, HIGH);
Serial.println("hellow i need assistance, room# 1");
Serial.println("hellow i need assistance, room# 1");
lastGreenStatus = HIGH;
timeG = millis();
}
else if (normValue1 >= 347 && normValue1 < 460 && lastGreenStatus == HIGH)
{
digitalWrite(R1Red, HIGH);
digitalWrite(R1Green, LOW);
Serial.println("further assistance needed, room# 1");
lastGreenStatus = LOW;
lastRedStatus = HIGH;
}
else if (normValue1 >= 460 && normValue1 <= 580 )
{
digitalWrite (R1Green, LOW);
digitalWrite (R1Red, LOW);
lastGreenStatus = LOW;
lastRedStatus = LOW;
timeD = ((millis() - timeG));
Serial.println("alarm disabled, room# 1");
Serial.print("The alarm took : ");
Serial.println(timeD);
Serial.println(" sec.");
}
}