An interesting phenonenon…this code is supposed to check the value of the light sensor and speak a message based on the value - one of two messages. All logic works fine except for one thing. There are two arrays of values that are sent to the SpeakJet - lightOn and goodMorning.
The problem is that if the first condition is true, SpeakJet will say the goodMorning array. But if the condition is false, it will say the lightOn array and then say the goodMorning array.
And if I reverse the order of the listing of the two arrays, it will have the opposite effect. So it appears that if SpeakJet is supposed to say the 2nd array, it will. But if it’s supposed to say the 1st array, it will say both of them.
I have tried a vast many things to solve this including the flush() method, etc but no effect. Any ideas?
here’s my code:
#include <NewSoftSerial.h>
// set up the SoftwareSerial port to connect to the SpeakJet
int lightPin = 0;
NewSoftSerial SpeakJetSerial = NewSoftSerial(2, 3);
char lightOn= {20, 96, 21, 114, 22, 128, 23, 2, 199, 7, 145, 128, 167, 8, 191, 151, 141, 8, 169, 8, 128, 145, 155, 191, 136, 136, 142};
char goodMorning = {20, 96, 21, 114, 22, 128, 23, 2, 8, 179, 138, 138, 177, 140, 7, 137, 7, 153, 141, 129, 143, 30, 10, 187, 191, 8, 131, 186, 132, 132, 141, 128, 128};
void setup()
{
SpeakJetSerial.begin(9600);
}
void loop()
{
int val;
int threshold = 500;
val=analogRead(lightPin);
if (val <= threshold) // light level goes from 0 to 900. Higher number is darker.
{
SpeakJetSerial.print(goodMorning); // send it to the SpeakJet
}
else
{
SpeakJetSerial.print(lightOn); // send it to the SpeakJet
}
delay (10000);
}