Phát triển Giải pháp Điều khiển Đèn & Đo Độ sáng đèn LED trên Nền tảng E-Ra.
Hướng dẫn cài đặt phần mềm thực hành
E-ra điều khiển độ sáng Led
E-ra đọc giá trị ánh sáng
int led = 2;
int freq = 5000;
int ledChannel = 0;
int resolution = 8;
ERaTimer timer;
/* This function print uptime every second */
void timerEvent() {
ERA_LOG("Timer", "Uptime: %d", ERaMillis() / 1000L);
int value = analogRead(34);
ERa.virtualWrite(V1, 4095 - value); // Reverse
}
ERA_WRITE(V0) {
/* Get value from Virtual Pin 0 and write Pin 2. */
uint8_t value = param.getInt();
#if (ESP_IDF_VERSION_MAJOR > 4)
ledcWrite(led, value * 255 / 100); // Range 0 - 255
#else
ledcWrite(ledChannel, value * 255 / 100); // Range 0 - 255
#endif
}
void setup() {
/* Setup debug console */
Serial.begin(115200);
ERa.begin(ssid, pass);
/* Setup timer called function every second */
timer.setInterval(1000L, timerEvent);
#if (ESP_IDF_VERSION_MAJOR > 4)
ledcAttach(led, freq, resolution);
#else
ledcSetup(ledChannel, freq, resolution);
ledcAttachPin(led, ledChannel);
#endif
}
void loop() {
ERa.run();
timer.run();
}
Tài liệu thuyết trình
Video E-Ra Workshop