First Commit
This commit is contained in:
commit
68458aadc0
21
Blink/Blink.ino
Normal file
21
Blink/Blink.ino
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
int buttonPin = D9;
|
||||||
|
int Led = A4;
|
||||||
|
int buttonState;
|
||||||
|
// the setup function runs once when you press reset or power the board
|
||||||
|
void setup() {
|
||||||
|
// initialize digital pin LED_BUILTIN as an output.
|
||||||
|
pinMode(Led, OUTPUT);
|
||||||
|
pinMode(buttonPin, INPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// the loop function runs over and over again forever
|
||||||
|
void loop() {
|
||||||
|
buttonState = digitalRead(buttonPin);
|
||||||
|
if (buttonState == LOW) {
|
||||||
|
digitalWrite(Led, HIGH);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
digitalWrite(Led, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
1
Blink/Blink.txt
Normal file
1
Blink/Blink.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Turn an LED on and off.
|
@ -0,0 +1,24 @@
|
|||||||
|
#include <esp_now.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
|
||||||
|
#define LED_PIN 2
|
||||||
|
|
||||||
|
void OnDataRecv(const uint8_t *mac, const uint8_t *incomingData, int len) {
|
||||||
|
digitalWrite(LED_PIN, *incomingData);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
WiFi.mode(WIFI_STA);
|
||||||
|
pinMode(LED_PIN, OUTPUT);
|
||||||
|
|
||||||
|
if (esp_now_init() != ESP_OK) {
|
||||||
|
Serial.println("Error initializing ESP-NOW");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uint8_t esp_now_register_recv_cb(OnDataRecv);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
#include <esp_now.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
|
||||||
|
#define BUTTON_PIN 1
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
WiFi.mode(WIFI_STA);
|
||||||
|
|
||||||
|
// Initialize ESP-NOW
|
||||||
|
if (esp_now_init() != ESP_OK) {
|
||||||
|
Serial.println("Error initializing ESP-NOW");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register peer (receiver's MAC address)
|
||||||
|
esp_now_peer_info_t peerInfo;
|
||||||
|
memcpy(peerInfo.peer_addr, receiverMACAddress, 6);
|
||||||
|
peerInfo.channel = 0;
|
||||||
|
peerInfo.encrypt = false;
|
||||||
|
|
||||||
|
if (esp_now_add_peer(&peerInfo) != ESP_OK) {
|
||||||
|
Serial.println("Failed to add peer");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pinMode(BUTTON_PIN, INPUT_PULLUP);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
if (digitalRead(BUTTON_PIN) == LOW) {
|
||||||
|
uint8_t data = 1;
|
||||||
|
esp_err_t result = esp_now_send(receiverMACAddress, &data, sizeof(data));
|
||||||
|
delay(50); // Debounce delay
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user