Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_NeoPixel.h>
- #include <TFT_eSPI.h> // Hardware-specific library
- TFT_eSPI tft; // Invoke custom library
- #define PIN BCM27
- #define NUMPIXELS 12
- #define SW7 BCM4
- #define SW6 BCM5
- Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
- bool toEdit = false;
- int menu = 0;
- int R_val, G_val, B_val, bright_val, led_num_val;
- int R_bar_val, G_bar_val, B_bar_val;
- void setup() {
- pinMode(SW7, INPUT_PULLUP);
- pinMode(SW6, INPUT_PULLUP);
- pixels.begin(); // This initializes the NeoPixel library.
- pixels.clear();
- pixels.show();
- tft.begin();
- tft.setRotation(3);
- tft.setTextSize(3);
- tft.fillScreen(TFT_BLACK);
- tft.drawString("LED AMOUNT:", 10, 10);
- tft.drawString("BRIGHTNESS:", 10, 60);
- tft.drawString("R:", 10, 110);
- tft.drawRect(48, 108, 154, 29, TFT_RED);
- tft.drawString("G:", 10, 160);
- tft.drawRect(48, 158, 154, 29, TFT_GREEN);
- tft.drawString("B:", 10, 210);
- tft.drawRect(48, 208, 154, 29, TFT_BLUE);
- analogReadResolution(12);
- }
- void loop() {
- if ((digitalRead(SW7) == LOW) && toEdit == false) {
- while (digitalRead(SW7) == LOW) { delay(200); }
- menu++;
- if (menu > 4) {
- menu = 0;
- }
- tft.fillRect(290, 0, 40, 240, TFT_BLACK);
- }
- if (digitalRead(SW6) == LOW) {
- while (digitalRead(SW6) == LOW) { delay(200); }
- toEdit = !toEdit;
- tft.fillRect(290, 0, 40, 240, TFT_BLACK);
- }
- switch (toEdit) {
- case true:
- {
- tft.fillTriangle(300, 20 + (50 * menu), 319, 10 + (50 * menu), 319, 30 + (50 * menu), TFT_RED);
- switch (menu) {
- case 0:
- {
- led_num_val = map(analogRead(1), 0, 4095, 0, 12);
- break;
- }
- case 1:
- {
- bright_val = map(analogRead(1), 0, 4095, 0, 255);
- break;
- }
- case 2:
- {
- R_val = map(analogRead(1), 0, 4095, 0, 255);
- R_bar_val = map(analogRead(1), 0, 4095, 0, 150);
- break;
- }
- case 3:
- {
- G_val = map(analogRead(1), 0, 4095, 0, 255);
- G_bar_val = map(analogRead(1), 0, 4095, 0, 150);
- break;
- }
- case 4:
- {
- B_val = map(analogRead(1), 0, 4095, 0, 255);
- B_bar_val = map(analogRead(1), 0, 4095, 0, 150);
- break;
- }
- }
- break;
- }
- case false:
- {
- tft.fillTriangle(300, 20 + (50 * menu), 319, 10 + (50 * menu), 319, 30 + (50 * menu), TFT_WHITE);
- break;
- }
- }
- tft.drawString(String(led_num_val) + " ", 210, 10);
- tft.drawString(String(bright_val) + " ", 210, 60);
- tft.fillRect(50, 110, R_bar_val, 25, TFT_RED);
- tft.fillRect(50 + R_bar_val, 110, 150 - R_bar_val, 25, TFT_BLACK);
- tft.drawString(String(R_val) + " ", 210, 110);
- tft.fillRect(50, 160, G_bar_val, 25, TFT_GREEN);
- tft.fillRect(50 + G_bar_val, 160, 150 - G_bar_val, 25, TFT_BLACK);
- tft.drawString(String(G_val) + " ", 210, 160);
- tft.fillRect(50, 210, B_bar_val, 25, TFT_BLUE);
- tft.fillRect(50 + B_bar_val, 210, 150 - B_bar_val, 25, TFT_BLACK);
- tft.drawString(String(B_val) + " ", 210, 210);
- pixels.setBrightness(bright_val);
- for (int j = 1; j <= led_num_val; j++) {
- pixels.setPixelColor(j - 1, pixels.Color(R_val, G_val, B_val));
- pixels.show(); // This sends the updated pixel color to the hardware.
- }
- for (int j = NUMPIXELS; j > led_num_val; j--) {
- pixels.setPixelColor(j - 1, pixels.Color(0, 0, 0));
- pixels.show(); // This sends the updated pixel color to the hardware.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement