Created
May 23, 2019 19:12
-
-
Save gilliangoud/ef47945a367781bbd044d9ad443ce95e to your computer and use it in GitHub Desktop.
Arduino file for a 2 digit remote controlled lap counter with a nrf24L - controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Keypad.h> | |
const byte ROWS = 4; | |
const byte COLS = 3; | |
#include <TM1637Display.h> | |
const int CLK = 3; //Set the CLK pin connection to the display | |
const int DIO = 2; //Set the DIO pin connection to the display | |
int NumStep = 0; //Variable to interate | |
TM1637Display display(CLK, DIO); //set up the 4-Digit Display. | |
char hexaKeys[ROWS][COLS] = { | |
{'1', '2', '3'}, | |
{'4', '5', '6'}, | |
{'7', '8', '9'}, | |
{'*', '0', '#'} | |
}; | |
byte rowPins[ROWS] = {7, 15, 16, 18}; | |
byte colPins[COLS] = {19, 8, 17}; | |
// NRF | |
#include "nRF24L01.h" //NRF24L01 library created by TMRh20 https://github.com/TMRh20/RF24 | |
#include "RF24.h" | |
#include "SPI.h" | |
RF24 radio(9,10); | |
const uint64_t pipe = 0xE6E6E6E6E6E6; // Needs to be the same for communicating between 2 NRF24L01 | |
int number = -1; | |
int number2 = -1; | |
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); | |
void setup(){ | |
Serial.begin(9600); | |
display.setBrightness(0x0a); //set the diplay to maximum brightness | |
radio.begin(); // Start the NRF24L01 | |
radio.openWritingPipe(pipe); // Get NRF24L01 ready to transmit | |
radio.setPALevel(RF24_PA_MAX); // RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX, RF24_PA_ERROR | |
} | |
void loop(){ | |
char customKey = customKeypad.getKey(); | |
if (customKey){ | |
//Serial.println(customKey); | |
if(customKey == 35){ | |
Serial.print(number); | |
radio.write(&number, sizeof(int)); | |
} else if(customKey == 42) { | |
if(number > -1){ | |
number--; | |
} | |
display.showNumberDec(number); | |
radio.write(&number, sizeof(int)); | |
} else { | |
if(number >= 10){ | |
number = -1; | |
} | |
if(number > 0){ | |
number = (customKey - 48) + number * 10; | |
} else { | |
number = customKey - 48; | |
} | |
display.showNumberDec(number); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment