// first set up some variables that will be used in the program
// r will be a random number that the program selects
// s will be the previous random number... just because we do not want to use the same number twice in a row
// delay1 is used to tell the program how much to pause between each step
// the other fields define the pins on the micro-controller board and define a sensor reading that will measure how much power you get from the generator
// the sensor reading could also pick up a reading from other sensors, such as a light sensor or motion detector
long r;
long s;
int SensorReading = 0;
int delay1=200;
int i=1;
const int ledPin = 10;
const int button = 9;
const int mysensor = A0;
void setup(){
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(mysensor,INPUT);
// if analog input pin 0 is unconnected, random analog
// noise will cause the call to randomSeed() to generate
// different seed numbers each time the sketch runs.
// randomSeed() will then shuffle the random function.
// or fill in a number to start the randomization, such as randomSeed(4)
randomSeed(1);
}
void loop() {
SensorReading = analogRead(mysensor); //Read the value of the A2 pin and assign that value to Val
char* myPoemArray[]={
"morning",
"evening",
"song",
"harmony",
"to",
"from",
"melody",
"sun",
"moon",
"silent",
"melody",
"start",
"over",
"go",
"return",
"one",
"may",
};
if (SensorReading<=300) {
digitalWrite(ledPin, HIGH); //If the sensor meets the IF condition then turn on the LED
// loop through this routine four times
// choose a random number and then print that word number from the array of words
// (unless it is a repeat of the previous word)
int x = 1;
for (int x = 0; x < 4; x = x + 1)
{
r = random(0, 17);
if (r==s)
{ }
else
{ Serial.print(myPoemArray[r]);
Serial.print(" ");
s=r;
delay(delay1);
}
}
// after looping four times, move to the next line
Serial.println(" ");
}
else {
digitalWrite(ledPin, LOW); //If anything else happens turn the LED off
delay(delay1);
}
}