Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This is a simple example of how to use the RXC6 4-Channel RF Receiver with an Arduino. This script will read the data from the four channels and print the status of each channel to the Serial monitor.
- This script reads the states of the four data pins whenever the VT pin goes high, indicating that a signal has been received. It then prints the status of each channel (either ON or OFF) to the Serial monitor whenever the state of a channel changes. This is done for all modes (Momentary, Latching, and Toggle).
- Please remember to adjust the pins according to your setup and the specific requirements of your project. Also, note that the interpretation of the signals may vary depending on the specific transmitter you're using.
- */
- // RXC6 4-Channel RF Receiver Example
- // Pin connections:
- // - ANT (1) to 32cm spiral antenna
- // - GND (2) to Arduino GND
- // - VT (5) to Arduino Pin 2 (or any other digital input pin)
- // - Data D0 (6) to Arduino Pin 3
- // - Data D1 (7) to Arduino Pin 4
- // - Data D2 (8) to Arduino Pin 5
- // - Data D3 (9) to Arduino Pin 6
- const int vtPin = 2;
- const int dataPins[] = {3, 4, 5, 6};
- const int numChannels = sizeof(dataPins) / sizeof(dataPins[0]);
- bool channelStates[numChannels];
- void setup() {
- Serial.begin(9600);
- pinMode(vtPin, INPUT);
- for (int i = 0; i < numChannels; i++) {
- pinMode(dataPins[i], INPUT);
- channelStates[i] = false;
- }
- }
- void loop() {
- if (digitalRead(vtPin) == HIGH) { // If a signal is received
- for (int i = 0; i < numChannels; i++) {
- bool newState = digitalRead(dataPins[i]);
- if (newState != channelStates[i]) {
- channelStates[i] = newState;
- Serial.print("Channel ");
- Serial.print(i);
- Serial.print(": ");
- Serial.println(newState ? "ON" : "OFF");
- }
- }
- }
- delay(100); // Delay to avoid flooding the serial port
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement