Jordan1711

attack

Mar 16th, 2018
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <FastLED.h>
  2. #define LED_PIN 8
  3. #define NUM_LEDS 80
  4. int butmove = 7;
  5. int butattack = 9;
  6. int i = 0;
  7. CRGB leds[NUM_LEDS];
  8. //unsigned long previousmillis = 0;
  9. //const long interval = 1000;
  10.  
  11. void setup() {
  12. FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  13. pinMode(butmove, INPUT);
  14. pinMode(butattack, INPUT);
  15. Serial.begin(9600);
  16.  
  17. }
  18.  
  19. /*int attack(int x, int interval){
  20. unsigned long currentmillis = millis();
  21.  
  22. leds[x-1]=CRGB(0,0,255);
  23. leds[x+1]=CRGB(0,0,255);
  24.  
  25. if(currentmillis - previousmillis >= interval) {
  26. previousmillis = currentmillis;
  27. }
  28.  
  29. leds[x-1]=CRGB(0,0, 0);
  30. leds[x+1]=CRGB(0,0,0);
  31.  
  32. } //new
  33.  
  34. int attack (int x, int interval){
  35. Serial.print("OK");
  36. leds[x-1] = CRGB(150,0,255);
  37. leds[x+1] = CRGB(150,0,255);
  38. FastLED.show();
  39. }
  40. */
  41. void loop() {
  42. unsigned long currentmillis = millis();
  43.  
  44. for(int i = 0; i < 80; i++) {
  45. leds[i] = CRGB(0, 0, 0);
  46. FastLED.show();
  47.  
  48. }
  49. for(int i = 0; i < 80; i++) {
  50. if(digitalRead(butattack) == HIGH) {
  51. // attack(i, 1000); //new
  52. Serial.print("OK");
  53. leds[i-1] = CRGB(150,0,255);
  54. leds[i+1] = CRGB(150,0,255);
  55. FastLED.show();
  56. }
  57. while(digitalRead(butmove) == LOW);
  58. leds[i - 1] = CRGB(0, 0, 0);
  59. leds[i] = CRGB(225, 0, 0);
  60. //leds[i + 1] = CRGB(225, 0, 0);
  61. FastLED.show();
  62. //i++;
  63. delay(50);
  64. }
  65. for(int i = 0; i < 80; i++) {
  66. leds[i] = CRGB(0, 0, 0);
  67. FastLED.show();
  68. i++;
  69. }
  70.  
  71. for(int i = 0; i < 80; i++) {
  72. leds[i] = CRGB(0, 255, 0);
  73. FastLED.show();
  74. //i++;
  75. }
  76. while(digitalRead(butmove) == LOW);
  77.  
  78. }
Add Comment
Please, Sign In to add comment