#include <Adafruit_CircuitPlayground.h>
#include <Adafruit_Circuit_Playground.h>
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
CircuitPlayground.begin();
delay(1000);
}
void loop() {
//define base timer amount
int timermax = 60;
//define range base minimum and maximum
int rlow = 1;
int rhigh = 100;
//define success variable
bool victory = false;
bool capture = true;
//define variable to be mapped as A2
int A2m = A2;
//button press generates random value and begins timer
if (A3 > 1000 && capture == true) {
int fish = random(rlow, rhigh);
victory = false;
capture = false;
//map potentiometer values to range
A2m = map(A2m, 0, 1023, rlow, rhigh);
for (int i = 0; i <= timermax; i++){
//potentiometer reading indicates if the player is left, right, or on top of the fish
//IF potentiometer is low light up left
if (A2m < fish) {
//Player fails if capture attempted
victory = false;
//Light up Left side
CircuitPlayground.setPixelColor(0, 0, 0, 255);
CircuitPlayground.setPixelColor(1, 0, 0, 255);
CircuitPlayground.setPixelColor(2, 0, 0, 255);
CircuitPlayground.setPixelColor(3, 0, 0, 255);
CircuitPlayground.setPixelColor(4, 0, 0, 255);
CircuitPlayground.setPixelColor(5, 0, 0, 255);
CircuitPlayground.setPixelColor(6, 0, 0, 255);
CircuitPlayground.setPixelColor(7, 0, 0, 255);
CircuitPlayground.setPixelColor(8, 255, 255, 0);
CircuitPlayground.setPixelColor(9, 255, 255, 0);
}
//IF potentiometer is high light up right
if (A2m > fish) {
//Player fails if capture attempted
victory = false;
//Light up Right side
CircuitPlayground.setPixelColor(0, 255, 255, 0);
CircuitPlayground.setPixelColor(1, 255, 255, 0);
CircuitPlayground.setPixelColor(2, 0, 0, 255);
CircuitPlayground.setPixelColor(3, 0, 0, 255);
CircuitPlayground.setPixelColor(4, 0, 0, 255);
CircuitPlayground.setPixelColor(5, 0, 0, 255);
CircuitPlayground.setPixelColor(6, 0, 0, 255);
CircuitPlayground.setPixelColor(7, 0, 0, 255);
CircuitPlayground.setPixelColor(8, 0, 0, 255);
CircuitPlayground.setPixelColor(9, 0, 0, 255);
}
//IF potentiometer equals light up both and make success true
if (A2m > fish) {
//Allow player to catch fish
victory = true;
//Light up Both sides
CircuitPlayground.setPixelColor(0, 255, 255, 0);
CircuitPlayground.setPixelColor(1, 255, 255, 0);
CircuitPlayground.setPixelColor(2, 0, 0, 255);
CircuitPlayground.setPixelColor(3, 0, 0, 255);
CircuitPlayground.setPixelColor(4, 0, 0, 255);
CircuitPlayground.setPixelColor(5, 0, 0, 255);
CircuitPlayground.setPixelColor(6, 0, 0, 255);
CircuitPlayground.setPixelColor(7, 0, 0, 255);
CircuitPlayground.setPixelColor(8, 255, 255, 0);
CircuitPlayground.setPixelColor(9, 255, 255, 0);
}
//accelerometer detects motion and provides feedback for a success or failure
if (CircuitPlayground.motionZ() > 10) {
//confirm that capture was attempted
capture = true;
//IF success equals true then light up green and increase difficulty
if (victory == true) {
//increase difficulty
timermax -= 5;
rlow = 1;
rhigh += 10;
//set timer variable to allow for next button press
i = timermax;
// Light up Green
CircuitPlayground.setPixelColor(0, 0, 255, 0);
CircuitPlayground.setPixelColor(1, 0, 255, 0);
CircuitPlayground.setPixelColor(2, 0, 255, 0);
CircuitPlayground.setPixelColor(3, 0, 255, 0);
CircuitPlayground.setPixelColor(4, 0, 255, 0);
CircuitPlayground.setPixelColor(5, 0, 255, 0);
CircuitPlayground.setPixelColor(6, 0, 255, 0);
CircuitPlayground.setPixelColor(7, 0, 255, 0);
CircuitPlayground.setPixelColor(8, 0, 255, 0);
CircuitPlayground.setPixelColor(9, 0, 255, 0);
delay(10);
CircuitPlayground.clearPixels();
}
//IF success does not equal true then light up red and reset difficulty
if (victory == false) {
//confirm that capture was attempted
capture = true;
//reset difficulty variables
timermax = 60;
rlow = 1;
rhigh = 100;
//set timer variable to allow for next button press
i = timermax;
//Light up Red
CircuitPlayground.setPixelColor(0, 255, 0, 0);
CircuitPlayground.setPixelColor(1, 255, 0, 0);
CircuitPlayground.setPixelColor(2, 255, 0, 0);
CircuitPlayground.setPixelColor(3, 255, 0, 0);
CircuitPlayground.setPixelColor(4, 255, 0, 0);
CircuitPlayground.setPixelColor(5, 255, 0, 0);
CircuitPlayground.setPixelColor(6, 255, 0, 0);
CircuitPlayground.setPixelColor(7, 255, 0, 0);
CircuitPlayground.setPixelColor(8, 255, 0, 0);
CircuitPlayground.setPixelColor(9, 255, 0, 0);
delay(10);
CircuitPlayground.clearPixels();
}
}
//IF timer run out fail if no catch attempted
if (i == timermax) {
if (capture == false) {
i = 0;
//reset difficulty variables
timermax = 60;
rlow = 1;
rhigh += 10;
//set timer variable and change capture variable to allow for next button press
i = timermax;
capture = true;
}
}
delay(10);
}
}
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.