Iam Using keypad 4*4 with an Ardunio Mega,I have sensors connected to the Ardunio I want to press a key from the keypad and have response in the same time,I dont want to wait till the loop continue, I want to save up to 10 numbers entered from the keypad,So is there a way to make the keypad as an interrupt for my code?
void loop() {
char key = kpd.getKey();
if (key != NO_KEY)
{
if (key == 'C') //clear the array
{
index = 0;
numbers[index] = '\0';
}
else if (key == '.')
{
numbers[index++] = '.';
numbers[index] = '\0';
}
else if (key >= '0' && key <= '9')
{
for(int z=0; z==10;z++)
{
numbers[index++] = key;
numbers[index] = '\0';
}
}
else if (key == 'A')
{
float len = atof(numbers); //conversion from string to numeric
if(fona.callPhone(numbers)){
Serial.println(F("RING!"));
Serial.print(F("Phone Number: "));
Serial.println(numbers); //print out on serial monitor
}
}
else if (key == 'D')
{
if ( fona.pickUp()) {
Serial.println(F("Failed"));
}
}else if (key == '#')
{
if ( fona.hangUp()) {
Serial.println(F("Failed"));
}
}}
gas =analogRead(gasPin);
dtostrf(gas, 4, 2,gass) ;
Serial.println(gas);
delay(1000); // Print value every 1 sec.
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
delay(150);
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
delay(300);
if (pirState == HIGH){
// we have just turned off
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
int ldrStatus = analogRead(ldrPin);
if (ldrStatus <=550) {
digitalWrite(led, HIGH);
Serial.println("LDR is DARK, LED is ON");
}
else {
digitalWrite(led, LOW);
}
valee = analogRead(tempPin);
float cel = (valee * 0.48828125)/2.12304;
dtostrf(cel, 4, 2,temp) ;
Serial.print("TEMPRATURE = ");
Serial.print(cel);
Serial.print("*C");
Serial.println();
delay(1000);
Aucun commentaire:
Enregistrer un commentaire