Guest User

Game project

a guest
Sep 28th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 0
  1. #include <FastLED.h>
  2.  
  3. // These definitions act similarly to an int value but are exclusive to the FastLED library.
  4.  
  5. #define NUM_LEDS 35 // PLEASE CHANGE TO APPROPRIATE AMOUNT OF PIXELS
  6. #define LED_PIN 6 // All the parts are connected to Arduino Digital Pin 6
  7. #define BRIGHTNESS 100 // Setting a brightness as a default
  8. #define SPEED 30 // Speed, to give physics to the 'ball' light later on
  9.  
  10. CRGB leds[NUM_LEDS];
  11. #define COLOR_ORDER RGB // Coded using (r,g,b) (default = GRB)
  12. int ledMode = 0; // Used to be able to create the 'boundaries' and level completions in the game
  13.  
  14. int sensorPin;
  15. int incomingPressure = 0;
  16. int dot = 0;
  17. int levelUp;
  18. int pressureNum;
  19. int pressureValue;
  20.  
  21. const byte GreenZoneLocation[] = {5, 10, 15, 20, 25, 30};
  22. byte greenZone = GreenZoneLocation[random(0, 6)];
  23.  
  24. int boundaryMiddle = greenZone;
  25.  
  26. int boundaryMin = greenZone - 3;
  27. int boundaryMinMid = greenZone - 2;
  28. int boundaryLower = greenZone - 1;
  29.  
  30. int boundaryMax = greenZone + 3;
  31. int boundaryMaxMid = greenZone + 2;
  32. int boundaryUpper = greenZone + 1;
  33.  
  34. int level = 0;
  35.  
  36. void setup() {
  37. randomSeed(analogRead(A0)); // Unused pins generate random sequences
  38. delay(2000); // safety power-up delay
  39. FastLED.addLeds<WS2812B, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  40. FastLED.setBrightness( BRIGHTNESS );
  41. Serial.begin(9600); // Activate the Serial monitor (Pressure sensor)
  42.  
  43. pinMode(LED_PIN, OUTPUT); // The NeoPixel strip is an output at pin 6.
  44. pinMode(sensorPin, INPUT); // The Vibration sensor is an input at pin A0.
  45. Serial.println(greenZone);
  46. }
  47.  
  48. void loop() {
  49.  
  50.  
  51.  
  52. int sensorPin = analogRead(2);
  53. int pressureNum = map(sensorPin, 0, 1023, 0, NUM_LEDS);
  54.  
  55. if (pressureNum > 3) {
  56. Serial.println(boundaryMin);
  57. delay(200);
  58. }
  59.  
  60. for (int dot = 3; dot < pressureNum; dot++) {
  61.  
  62. leds[dot] = CHSV(160, 255, 100);
  63. FastLED.show();
  64. //Serial.println(dot);
  65. leds[dot] = CHSV(0, 0, 0);
  66. delay( SPEED );
  67.  
  68. }
  69.  
  70. leds[boundaryMiddle] = CRGB(255, 0, 0);
  71. leds[boundaryMin] = CRGB(255, 0, 0);
  72. leds[boundaryMinMid] = CRGB(255, 0, 0);
  73. leds[boundaryLower] = CRGB(255, 0, 0);
  74. leds[boundaryMax] = CRGB(255, 0, 0);
  75. leds[boundaryMaxMid] = CRGB(255, 0, 0);
  76. leds[boundaryUpper] = CRGB(255, 0, 0);
  77.  
  78. if (dot > boundaryMin && dot < boundaryMax) {
  79. levelUp = 1;
  80. } else {
  81. levelUp = 0;
  82. }
  83.  
  84. switch (levelUp) {
  85. case 1:
  86. {
  87. loop();
  88. FastLED.clear();
  89. fill_rainbow (leds, NUM_LEDS, 0, 255);
  90. greenZone = GreenZoneLocation[random(0, 6)];
  91.  
  92. if (levelUp == 1) {
  93. level = 1;
  94. } else if (level == 1) {
  95. level = 2;
  96. } else if (level == 2) {
  97. level = 3;
  98. } else if (level == 3) {
  99. fill_rainbow (leds, NUM_LEDS, 0, 255);
  100. levelUp = 0;
  101. }
  102. }
  103. break;
  104. case 0:
  105. {
  106. loop();
  107. }
  108. break;
  109. }
  110.  
  111. switch (level) {
  112. case 0: {
  113.  
  114. }
  115. case 1: {
  116.  
  117. leds[boundaryMin] = CRGB(0, 0, 0);
  118. leds[boundaryMax] = CRGB(0, 0, 0);
  119. }
  120. break;
  121. case 2: {
  122.  
  123. leds[boundaryMin] = CRGB(0, 0, 0);
  124. leds[boundaryMax] = CRGB(0, 0, 0);
  125. leds[boundaryMinMid] = CRGB(0, 0, 0);
  126. leds[boundaryMaxMid] = CRGB(0, 0, 0);
  127. }
  128. break;
  129. case 3: {
  130.  
  131. leds[boundaryMin] = CRGB(0, 0, 0);
  132. leds[boundaryMax] = CRGB(0, 0, 0);
  133. leds[boundaryMinMid] = CRGB(0, 0, 0);
  134. leds[boundaryMaxMid] = CRGB(0, 0, 0);
  135. leds[boundaryUpper] = CRGB(0, 0, 0);
  136. leds[boundaryLower] = CRGB(0, 0, 0);
  137. }
  138. break;
  139.  
  140. }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment