Advertisement
timor2542

VEC2023 REGION LAB Q3

Dec 21st, 2023
1,114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 2.74 KB | Writing | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2. #include <TFT_eSPI.h>  // Hardware-specific library
  3.  
  4. TFT_eSPI tft;  // Invoke custom library
  5.  
  6. #define PIN D0
  7. #define NUMPIXELS 12
  8.  
  9. Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
  10.  
  11. #define WHITE pixels.Color(255, 255, 255)
  12. #define RED pixels.Color(255, 0, 0)
  13. #define YELLOW pixels.Color(255, 255, 0)
  14. #define GREEN pixels.Color(0, 255, 0)
  15. #define SKYBLUE pixels.Color(0, 255, 255)
  16. #define BLUE pixels.Color(0, 0, 255)
  17. #define PURPLE pixels.Color(255, 0, 255)
  18. #define OFF pixels.Color(0, 0, 0)
  19.  
  20. int color_choice[7] = { WHITE, RED, YELLOW, GREEN, SKYBLUE, BLUE, PURPLE };
  21. String direction[2] = { "CW", "CCW" };
  22. String pattern[2] = { "DEFAULT", "INVERT" };
  23. String text_color_choice[7] = { "WHITE", "RED", "YELLOW", "GREEN", "SKYBLUE", "BLUE", "PURPLE" };
  24. int tft_text_color[7] = { TFT_WHITE, TFT_RED, TFT_YELLOW, TFT_GREEN, TFT_CYAN, TFT_BLUE, TFT_MAGENTA };
  25.  
  26. int i = 0;
  27. int icolor = 0;
  28. int isCCW = 0;
  29. int invert_pattern = 0;
  30.  
  31. void setup() {
  32.  
  33.   pinMode(WIO_KEY_C, INPUT_PULLUP);
  34.   pinMode(WIO_KEY_B, INPUT_PULLUP);
  35.   pinMode(WIO_KEY_A, INPUT_PULLUP);
  36.  
  37.   tft.begin();
  38.   tft.setRotation(3);
  39.   tft.setTextSize(3);
  40.   tft.fillScreen(TFT_BLACK);
  41.  
  42.   tft.drawString("DIRECTION:", 10, 50);
  43.   tft.drawString("PATTERN:", 10, 100);
  44.   tft.drawString("COLOR:", 10, 150);
  45.  
  46.   pixels.begin();  // This initializes the NeoPixel library.
  47.   pixels.setBrightness(10);
  48.   pixels.show();
  49. }
  50.  
  51. void loop() {
  52.   if (digitalRead(WIO_KEY_C) == LOW) {
  53.     while (digitalRead(WIO_KEY_C) == LOW) { delay(200); }
  54.     isCCW ^= 1;
  55.   }
  56.  
  57.   if (digitalRead(WIO_KEY_B) == LOW) {
  58.     while (digitalRead(WIO_KEY_B) == LOW) { delay(200); }
  59.     invert_pattern ^= 1;
  60.   }
  61.  
  62.   if (digitalRead(WIO_KEY_A) == LOW) {
  63.     while (digitalRead(WIO_KEY_A) == LOW) { delay(200); }
  64.     icolor++;
  65.     if (icolor > 6) { icolor = 0; }
  66.   }
  67.  
  68.   if (isCCW) {
  69.     i--;
  70.   } else {
  71.     i++;
  72.   }
  73.  
  74.   if (i < 0) { i = NUMPIXELS - 1; }
  75.   if (i > NUMPIXELS - 1) { i = 0; }
  76.  
  77.   tft.drawString(String(direction[isCCW]) + "   ", 200, 50);
  78.   tft.drawString(String(pattern[invert_pattern]) + "   ", 180, 100);
  79.  
  80.   tft.setTextColor(tft_text_color[icolor], TFT_BLACK);  // (Text Color, Text Background Color)
  81.   tft.drawString(String(text_color_choice[icolor]) + "   ", 180, 150);
  82.   tft.setTextColor(TFT_WHITE, TFT_BLACK);  // (Text Color, Text Background Color)
  83.  
  84.   if (invert_pattern) {
  85.     for (int j = 0; j < NUMPIXELS; j++) {
  86.       pixels.setPixelColor(j, color_choice[icolor]);
  87.     }
  88.     pixels.setPixelColor(i, OFF);
  89.     pixels.show();
  90.   } else {
  91.     for (int j = 0; j < NUMPIXELS; j++) {
  92.       pixels.setPixelColor(j, OFF);
  93.     }
  94.     pixels.setPixelColor(i, color_choice[icolor]);
  95.     pixels.show();
  96.   }
  97.   delay(150);
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement