Skip to content
Snippets Groups Projects
Unverified Commit 1b91a289 authored by alberto.malagamba@studenti.unimi.it's avatar alberto.malagamba@studenti.unimi.it
Browse files

First commmit

parents
Branches
No related tags found
No related merge requests found
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}
This diff is collapsed.
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
chris--a/Keypad@3.1.1
\ No newline at end of file
#include <Keypad.h>
#define ROW_NUM 4
#define COLUMN_NUM 4
#define LED_BUILTIN 2
char keys[ROW_NUM][COLUMN_NUM] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte pin_rows[ROW_NUM] = {19, 18, 5, 17}; // GPIO19, GPIO18, GPIO5, GPIO17 connect to the row pins
byte pin_column[COLUMN_NUM] = {16, 4, 0, 2}; // GPIO16, GPIO4, GPIO0, GPIO2 connect to the column pins
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
boolean blink = false;
boolean ledPin_state;
int boom = 0;
byte ledPin = LED_BUILTIN;
void keypadEvent(KeypadEvent key){
switch (keypad.getState()){
case PRESSED:
if (key == '#') {
digitalWrite(ledPin,!digitalRead(ledPin));
ledPin_state = digitalRead(ledPin); // Remember LED state, lit or unlit.
}
break;
case RELEASED:
if (key == '*') {
digitalWrite(ledPin,ledPin_state); // Restore LED state from before it started blinking.
blink = false;
}
break;
case HOLD:
if (key == '*') {
blink = true; // Blink the LED when holding the * key.
}
break;
}
}
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(ledPin, HIGH); // Turn the LED on.
ledPin_state = digitalRead(ledPin); // Store initial LED state. HIGH when LED is on.
keypad.addEventListener(keypadEvent); // Add an event listener for this keypad
}
void loop() {
//Serial.print('Boom');
while(Serial.available() == 0){
Serial.println("Boom");
delay(1000);
}
if(Serial.available() > 0){
//Serial.print('No boom boom');
String msg = Serial.readString();
msg.trim();
if(msg == "Boom Boom"){
Serial.println("Recived something ...");
boom = 1;
}
}
if(boom == 1){
Serial.print("Waiting for new input:");
delay(5000);
char key = keypad.getKey();
if(key) {
Serial.println(key);
}
}
delay(1000);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment