// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
#define PIXEL_PIN D4
#define PIXEL_COUNT 17
#define PIXEL_TYPE WS2812
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
int potPin = A0;
int buttonPin = D2;
int potReading = 0;
int servoPin = A4;
Servo myServo;
int servoPos = 0;
int speakerPin = D0;
void processanswers(void);
//int number_of_questions = 1;
bool correctness[] = {false};
int correctanswers[] = {1};
int playeranswers[1];
int count = 0;
bool first_encounter = true;
int buttonState;
long lastDebounceTime = 0;
long debounceDelay = 2500;
long gamewait = 300000;
int soundpin[] = {D5,D6,D7};
int pin4 = D8;
int R = 0;
int G = 0;
int B = 255;
void setup() {
strip.begin();
strip.show();
setcolor();
pinMode(D5, OUTPUT);
pinMode(D6, OUTPUT);
pinMode(D7, OUTPUT);
digitalWrite(soundpin[0], LOW);
digitalWrite(soundpin[1], LOW);
digitalWrite(soundpin[2], LOW);
pinMode( buttonPin , INPUT_PULLUP);
myServo.attach(servoPin);
myServo.write(0);
Particle.variable("pot",potReading);
Particle.variable("count",count);
}
void loop() {
buttonState = digitalRead(buttonPin);
potReading = analogRead(potPin);
if ( (millis() - lastDebounceTime) > debounceDelay) {
if (buttonState == LOW) {
lastDebounceTime = millis();
processanswers();
}
}
delay(10);
}
void processanswers(){
playeranswers[count] = (int)(potReading/1000);
if (playeranswers[count] == correctanswers[count] && !first_encounter){
correctness[count] = true;
}
checkanswers();
}
void checkanswers(){
if (first_encounter){
R = 0;
G = 255;
B = 0;
setcolor();
voiceline(0);
delay(12000);
voiceline(1);
setcolor();
first_encounter = false;
}
else {
if (correctness[count] == false) {
R = 255;
G = 0;
B = 0;
setcolor();
delay(10);
setcolor();
voiceline(1);
count = 0;
}
else if (correctness[count] == true){
R = 0;
G = 255;
B = 0;
setcolor();
delay(10);
setcolor();
count ++;
}
if (count == 1){
R = 255;
G = 0;
B = 255;
setcolor();
voiceline(2);
delay(5000);
myServo.write(90);
delay(20000);
myServo.write(0);
setcolor();
count = 0;
first_encounter = true;
for(int i = 0; i <= 1; i++){
correctness[i] = false;
}
}
}
}
void setcolor(){
uint16_t j;
uint32_t c = strip.Color(R, G, B);
for(j=0; j< strip.numPixels(); j++){
strip.setPixelColor(j, c );
strip.show();
}
if ((R == 255) or (G == 255)) {
delay(500);
R = 0;
G = 0;
B = 255;
}
}
void voiceline(int voicenumber){
digitalWrite(soundpin[voicenumber], HIGH);
delay(1000);
digitalWrite(soundpin[voicenumber],LOW);
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .