Hi all,
I have a project where I have a PIR motion sensor looking for motion. When it's triggered, a random letter between A - L is sent as a keystroke. Otherwise, it keeps looking for motion.
I've been told that rather than having a random letter generate now, I need to have it send a letter as a keystroke from a list of letters in a sequence.
Please see the code I have that works for sending a random letter in the array when motion is detected. How would I change this to continue to look for motion and move down the list of letters in order? I will ultimately be putting a much longer series of letters in the array.
int PIR = 9;
const byte randomLetters = 20;
char* letters[randomLetters] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"};
void setup()
{
pinMode(PIR, INPUT);
Keyboard.begin();
randomSeed(analogRead(0));
Serial.begin(9600);
}
void loop()
{
if (digitalRead(PIR) == HIGH)
{
Keyboard.print(letters[random(0,randomLetters)]);
delay(2000);
}
else
{
Serial.println("No Motion");
}
delay(500);
}