Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- // These definitions act similarly to an int value but are exclusive to the FastLED library.
- #define NUM_LEDS 35 // PLEASE CHANGE TO APPROPRIATE AMOUNT OF PIXELS
- #define LED_PIN 6 // All the parts are connected to Arduino Digital Pin 6
- #define BRIGHTNESS 100 // Setting a brightness as a default
- #define SPEED 30 // Speed, to give physics to the 'ball' light later on
- CRGB leds[NUM_LEDS];
- #define COLOR_ORDER RGB // Coded using (r,g,b) (default = GRB)
- int ledMode = 0; // Used to be able to create the 'boundaries' and level completions in the game
- int sensorPin;
- int incomingPressure = 0;
- int dot = 0;
- int levelUp;
- int pressureNum;
- int pressureValue;
- const byte GreenZoneLocation[] = {5, 10, 15, 20, 25, 30};
- byte greenZone = GreenZoneLocation[random(0, 6)];
- int boundaryMiddle = greenZone;
- int boundaryMin = greenZone - 3;
- int boundaryMinMid = greenZone - 2;
- int boundaryLower = greenZone - 1;
- int boundaryMax = greenZone + 3;
- int boundaryMaxMid = greenZone + 2;
- int boundaryUpper = greenZone + 1;
- int level = 0;
- void setup() {
- randomSeed(analogRead(A0)); // Unused pins generate random sequences
- delay(2000); // safety power-up delay
- FastLED.addLeds<WS2812B, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
- FastLED.setBrightness( BRIGHTNESS );
- Serial.begin(9600); // Activate the Serial monitor (Pressure sensor)
- pinMode(LED_PIN, OUTPUT); // The NeoPixel strip is an output at pin 6.
- pinMode(sensorPin, INPUT); // The Vibration sensor is an input at pin A0.
- Serial.println(greenZone);
- }
- void loop() {
- int sensorPin = analogRead(2);
- int pressureNum = map(sensorPin, 0, 1023, 0, NUM_LEDS);
- if (pressureNum > 3) {
- Serial.println(boundaryMin);
- delay(200);
- }
- for (int dot = 3; dot < pressureNum; dot++) {
- leds[dot] = CHSV(160, 255, 100);
- FastLED.show();
- //Serial.println(dot);
- leds[dot] = CHSV(0, 0, 0);
- delay( SPEED );
- }
- leds[boundaryMiddle] = CRGB(255, 0, 0);
- leds[boundaryMin] = CRGB(255, 0, 0);
- leds[boundaryMinMid] = CRGB(255, 0, 0);
- leds[boundaryLower] = CRGB(255, 0, 0);
- leds[boundaryMax] = CRGB(255, 0, 0);
- leds[boundaryMaxMid] = CRGB(255, 0, 0);
- leds[boundaryUpper] = CRGB(255, 0, 0);
- if (dot > boundaryMin && dot < boundaryMax) {
- levelUp = 1;
- } else {
- levelUp = 0;
- }
- switch (levelUp) {
- case 1:
- {
- loop();
- FastLED.clear();
- fill_rainbow (leds, NUM_LEDS, 0, 255);
- greenZone = GreenZoneLocation[random(0, 6)];
- if (levelUp == 1) {
- level = 1;
- } else if (level == 1) {
- level = 2;
- } else if (level == 2) {
- level = 3;
- } else if (level == 3) {
- fill_rainbow (leds, NUM_LEDS, 0, 255);
- levelUp = 0;
- }
- }
- break;
- case 0:
- {
- loop();
- }
- break;
- }
- switch (level) {
- case 0: {
- }
- case 1: {
- leds[boundaryMin] = CRGB(0, 0, 0);
- leds[boundaryMax] = CRGB(0, 0, 0);
- }
- break;
- case 2: {
- leds[boundaryMin] = CRGB(0, 0, 0);
- leds[boundaryMax] = CRGB(0, 0, 0);
- leds[boundaryMinMid] = CRGB(0, 0, 0);
- leds[boundaryMaxMid] = CRGB(0, 0, 0);
- }
- break;
- case 3: {
- leds[boundaryMin] = CRGB(0, 0, 0);
- leds[boundaryMax] = CRGB(0, 0, 0);
- leds[boundaryMinMid] = CRGB(0, 0, 0);
- leds[boundaryMaxMid] = CRGB(0, 0, 0);
- leds[boundaryUpper] = CRGB(0, 0, 0);
- leds[boundaryLower] = CRGB(0, 0, 0);
- }
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment