I'm looking at sending sensor values to another arduino using either the serial or i2c. Basically the keypad sets a value, then the sensor counts from that value. I want those counted values (v1 in the code) sent to another arduinos serial monitor. I've played around with both a little bit but to no avail.
#include <Keypad.h>
int pirPin = 10; //Sensor code
int counter = 0;//Sensor code
int laststate = HIGH; //Sensor code
int num = 0;
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
pinMode(pirPin,INPUT_PULLUP); //Sensor code
}
void loop()
{
int v1 = GetNumber();
while (v1 > 0 )
{
int state = digitalRead(pirPin);
if (laststate == LOW && state == HIGH) // only count on a LOW-> HIGH transition
{
v1--;
Serial.println(v1);
}
laststate = state; // remember last state
}
}
int GetNumber()
{
char key = kpd.getKey();
while(key != '#')
{
switch (key)
{
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
Serial.print(key);
num = num * 10 + (key - '0');
break;
case '*':
num = 0;
break;
}
key = kpd.getKey();
}
return num;
}