Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Rev 0 Created 7/7/2022 This is a limited version of Reference 1 focusing only on 4 pushbuttons - Transmitter Code
- //Rev 1 Created 7/9/2022 This is my successful attempt to introduce a pause after each reading of the pushbuttons without using the delay function. This has the effect of working as a speed control too by adjusting the interval value. interval=10 seems to be a good speed.
- //Rev 2 Created 7/14/2022 This is my successfull attempt to create a 13 pushbutton transmitter
- #include <SPI.h>
- #include <nRF24L01.h>
- #include <RF24.h>
- const int PB1p=2, PB2p=3, PB3p=4, PB4p=5, PB5p=6, PB6p=7, PB7p=10; //Pin numbers for Pushbutton Pins
- const uint64_t pipeOut = 0xF9E8F0F0E1LL; //IMPORTANT: The same as in the receiver 0xF9E8F0F0E1LL
- RF24 radio(8, 9); // select CE,CSN pin
- struct PacketData
- {
- byte switch1Value;
- byte switch2Value;
- byte switch3Value;
- byte switch4Value;
- byte switch5Value;
- byte switch6Value;
- byte switch7Value;
- byte switch8Value;
- byte switch9Value;
- byte switch10Value;
- byte switch11Value;
- byte switch12Value;
- byte switch13Value;
- };
- PacketData data;
- unsigned long previousMillis = 0;
- unsigned long interval = 10;
- void setup()
- {
- radio.begin();
- radio.setDataRate(RF24_250KBPS);
- radio.openWritingPipe(pipeOut);
- radio.stopListening(); //start the radio Transmitter
- pinMode(PB1p,INPUT_PULLUP); //PB1
- pinMode(PB2p,INPUT_PULLUP); //PB2
- pinMode(PB3p,INPUT_PULLUP); //PB3
- pinMode(PB4p,INPUT_PULLUP); //PB4
- pinMode(PB5p,INPUT_PULLUP); //PB5
- pinMode(PB6p,INPUT_PULLUP); //PB6
- pinMode(PB7p,INPUT_PULLUP); //PB7
- pinMode(A0,INPUT_PULLUP); //PB8
- pinMode(A1,INPUT_PULLUP); //PB9
- pinMode(A2,INPUT_PULLUP); //PB10
- pinMode(A3,INPUT_PULLUP); //PB11
- pinMode(A4,INPUT_PULLUP); //PB12
- pinMode(A5,INPUT_PULLUP); //PB13
- }
- void loop()
- {
- unsigned long currentMillis = millis();
- if (currentMillis - previousMillis > interval)
- {
- previousMillis = currentMillis;
- data.switch1Value = !digitalRead(PB1p);
- data.switch2Value = !digitalRead(PB2p);
- data.switch3Value = !digitalRead(PB3p);
- data.switch4Value = !digitalRead(PB4p);
- data.switch5Value = !digitalRead(PB5p);
- data.switch6Value = !digitalRead(PB6p);
- data.switch7Value = !digitalRead(PB7p);
- data.switch8Value = !digitalRead(A0);
- data.switch9Value = !digitalRead(A1);
- data.switch10Value = !digitalRead(A2);
- data.switch11Value = !digitalRead(A3);
- data.switch12Value = !digitalRead(A4);
- data.switch13Value = !digitalRead(A5);
- radio.write(&data, sizeof(PacketData));
- } //End of millis interval if statement
- } //End of void loop()
- //References
- //Reference 1- Adaptation of https://www.youtube.com/watch?v=gsHeNrDoK84&t=14s which is the "Hash Include Electronics" YouTube channel video "Arduino 10 Channels Wireless Transmitter Receiver | nrf24l01+| DIY" File Located at https://github.com/un0038998/10_Channel_NRF_Transmitter_Receiver
- //Reference 2- https://www.baldengineer.com/blink-without-delay-explained.html
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement