Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h> // https://arduino.cc/reference/en/language/functions/communication/wire
- #include <LiquidCrystal_I2C.h> // https://arduinolibraries.info/libraries/liquid-crystal-i2-c
- #include <ESP32RotaryEncoder.h> // https://arduinolibraries.info/libraries/esp32-rotary-encoder https://tinyurl.com/rotenc
- #include <TM1638plus.h> // https://arduinolibraries.info/libraries/tm1638plus
- #include <LedControl.h> // https://arduino.cc/reference/en/libraries/ledcontrol
- #include <FastLED.h> // https://fastled.io/
- #include <WiFi.h> // https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/src/WiFi.h
- #define SCK 16 // SPI clock
- #define DTA 17 // SPI data
- #define CS_tm 4 // TM1638 chip select
- #define CS_m7 5 // MAX7219 chip select
- #define CLK 14 // Rotary Encoder pin A
- #define DT 27 // Rotary Encoder pin B
- #define SW 26 // Rotary Encoder switch
- #define DIN 2 // WS2812b strip data
- #define CHIPSET WS2812B // led type
- #define COLOR_ORDER GRB // Green Red Blue
- #define NUM_LEDS 32 // strip length
- int brightness = 45; // initial brightness setting
- LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C LCD (newer versions use the adress 0x3F)
- RotaryEncoder rot(CLK, DT, SW); // KY-040 rotary encoder module with on-board pull-up resistors
- TM1638plus tm(CS_tm, SCK, DTA, false); // TM1638 module (bool high_freq: true if high freq CPU > ~100 MHZ)
- LedControl ledm(DTA, SCK, CS_m7, 0); // Max7219 LED matrix (address 0)
- CRGB leds[NUM_LEDS]; // WS2812B LED strip
- char line0[17]; // arrays for 16 character LCD screen rows
- char line1[17]; // (extra character for the null terminator)
- int selection = 50; // initial value for rotary encoder value
- const int lowerBoundary = 0;
- const int upperBoundary = 99;
- const bool wrap = false;
- const char* ssid = "ssid";
- const char* password = "password";
- void setup() {
- lcd.init(); // initialize the LCD module
- lcd.backlight(); // turn on the backlight
- lcd.clear(); // clear the screen
- tm.displayBegin(); // initialize the TM1638 module
- tm.reset();
- tm.setLED(0, 1); // turn on 1st LED
- ledm.shutdown(0, false); // initialize the Max7219 module
- ledm.setIntensity(0, 0); // address, brightness (0-15)
- ledm.clearDisplay(0); // turn off all LEDs
- rot.setEncoderType(EncoderType::HAS_PULLUP);
- // rot.setEncoderType(EncoderType::SW_FLOAT);
- rot.setBoundaries(lowerBoundary, upperBoundary, wrap);
- rot.onTurned(&knobCallback);
- rot.onPressed(&buttonCallback);
- rot.begin(); // configure inputs and the attach interrupts
- lcd.setCursor(0, 0); // position cursor to column 0, line 0
- lcd.print("BlinkenLights");
- lcd.setCursor(0, 1); // position cursor to column 0, line 1
- lcd.print(" DEV PLATFORM");
- FastLED.addLeds<CHIPSET, DIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- FastLED.setBrightness(brightness);
- randomSeed(31415926);
- connectWiFi();
- lcd.clear();
- }
- void loop() {
- tm.displayIntNum(millis(), true, TMAlignTextRight); // millisecond counter
- ledm.setLed(0, random(8), random(8), true); // turn on a random LED
- ledm.setLed(0, random(8), random(8), false); // turn off a ramdon LED
- sinelon(); // color dot sweeping back and forth, with fading trails
- FastLED.show(); // (from FastLED example "DemoReel100")
- }
- void knobCallback(long value) {
- lcd.setCursor(0, 1); // position cursor to column 0, line 1
- lcd.print("Selecting: ");
- selection = value;
- lcd.print(value);
- lcd.print(" ");
- }
- void buttonCallback(unsigned long duration) {
- lcd.setCursor(0, 0); // position cursor to column 0, line 0
- lcd.print("Selection: ");
- lcd.print(selection);
- lcd.print(" ");
- }
- void sinelon() {
- fadeToBlackBy(leds, NUM_LEDS, 4); // amount to fade by (lower value = longer trail)
- int pos = beatsin16(17, 0, NUM_LEDS - 1); // beats per minute, lowest, highest
- leds[pos] += CHSV(96, 255, brightness); // hue, saturation, brightness
- }
- void connectWiFi() {
- delay(3000);
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("connecting WiFi");
- lcd.setCursor(3, 1);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- lcd.print(".");
- }
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("WiFi connected:");
- lcd.setCursor(1, 1);
- lcd.print(WiFi.localIP());
- delay(3000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement