Usage Example for Arduino-Multi-State Signal Trigger
-
Control the transmitter to emit a variety of signals
-
Take Arduino as an example, the other main controllers use the same principle, only need to connect to the corresponding digital port.
-
Take inching mode in the receiver as an example, the principles of other modes are the same
Hardware Preparation
- DFRuino UNO R3 + Gravity: IO Expansion Shield x1
- Wireless switch transmitter x1
- Wireless switch receiver x1
- 3.3-5V power supply x 1
- Button x 2
Software Preparation
Connection
Transmitting end :
Receiving end:
Sample code
Receiving end:
#define Button_D2 2//Arduino
#define Button_D3 3//Arduino
//#define Button_D2 D2 //ESP32
//#define Button_D3 D3 //ESP32
void setup() {
Serial.begin(115200);
pinMode(Button_D2, INPUT);
pinMode(Button_D3, INPUT);
}
void loop() {
if (((digitalRead(Button_D2)==0) && (digitalRead(Button_D3)==0))) {
Serial.println("State:1,Pressed:NONE");
delay(500);
}
if (((digitalRead(Button_D2)==0) && (digitalRead(Button_D3)==1))) {
Serial.println("State:2,Pressed:D3");
delay(500);
}
if (((digitalRead(Button_D2)==1) && (digitalRead(Button_D3)==0))) {
Serial.println("State:3,Pressed:D2");
delay(500);
}
if (((digitalRead(Button_D2)==1) && (digitalRead(Button_D3)==1))) {
Serial.println("State:4,Pressed:D2&D3");
delay(500);
}
delay(100);
}
Result
Press different key combinations, the serial port will print different status values.
Was this article helpful?
