96 lines
2.1 KiB
C++
96 lines
2.1 KiB
C++
#include <Adafruit_GFX.h>
|
|
#include <Adafruit_NeoPixel.h>
|
|
#include <Adafruit_SSD1306.h>
|
|
#include <Arduino.h>
|
|
#include <Wire.h>
|
|
|
|
#define BUTTON_IN_1 GPIO_NUM_27
|
|
#define RGB_PIN GPIO_NUM_15
|
|
#define LED_COUNT 1
|
|
|
|
Adafruit_NeoPixel pixels(1, RGB_PIN, NEO_GRB + NEO_KHZ800);
|
|
Adafruit_SSD1306 display(128, 64, &Wire, -1);
|
|
|
|
bool i2c_scanner() {
|
|
uint8_t error, address;
|
|
int nDevices;
|
|
|
|
Serial.println("Scanning sensors on I2C Bus...");
|
|
|
|
for (address = 1; address < 127; address++) {
|
|
Wire.beginTransmission(address);
|
|
error = Wire.endTransmission();
|
|
|
|
if (error == 0) {
|
|
Serial.print("I2C device found at address 0x");
|
|
if (address < 16)
|
|
Serial.print("0");
|
|
Serial.println(address, HEX);
|
|
} else if (error == 4) {
|
|
Serial.print("Unknown error at address 0x");
|
|
if (address < 16)
|
|
Serial.print("0");
|
|
Serial.println(address, HEX);
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
Serial.println("Main.setup");
|
|
|
|
Wire.begin();
|
|
|
|
pixels.begin();
|
|
pixels.clear();
|
|
pixels.show();
|
|
pixels.setBrightness(10);
|
|
|
|
i2c_scanner();
|
|
|
|
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
|
|
Serial.println(F("SSD1306 allocation failed"));
|
|
for (;;)
|
|
; // Don't proceed, loop forever
|
|
}
|
|
|
|
display.clearDisplay();
|
|
|
|
display.setTextSize(2);
|
|
display.setTextColor(SSD1306_WHITE);
|
|
display.setCursor(10, 0);
|
|
display.println(F("Hallo Welt"));
|
|
display.display();
|
|
}
|
|
|
|
uint16_t hsv = 0;
|
|
uint32_t hsvUpdate = 0;
|
|
uint32_t btnPressStartTime = 0;
|
|
uint8_t isBtnPressed = 0;
|
|
|
|
void loop() {
|
|
uint32_t now = millis();
|
|
|
|
int btnIn1 = digitalRead(BUTTON_IN_1);
|
|
|
|
if (btnIn1 == HIGH && isBtnPressed == 0) {
|
|
btnPressStartTime = now;
|
|
isBtnPressed = 1;
|
|
Serial.println("BTN pressed");
|
|
}
|
|
if (btnIn1 == LOW && isBtnPressed == 1) {
|
|
isBtnPressed = 0;
|
|
}
|
|
|
|
if (now - hsvUpdate >= 100) {
|
|
hsv += 100;
|
|
if (hsv >= 65535) hsv = 0;
|
|
|
|
pixels.setPixelColor(0, pixels.ColorHSV(hsv));
|
|
pixels.show();
|
|
|
|
hsvUpdate = now;
|
|
}
|
|
} |