/*
Arduino | coding-help
I need help with this code!
Scotty — 6/22/24 at 2:07 AM
https://raw.githubusercontent.com/epsilonrt/RadioHead/master/examples/ask/ask_receiver/ask_receiver.pde
*/
// ask_receiver.pde
// -*- mode: C++ -*-
// Simple example of how to use RadioHead to receive messages
// with a simple ASK transmitter in a very simple way.
// Implements a simplex (one-way) receiver with an Rx-B1 module
// Tested on Arduino Mega, Duemilanova, Uno, Due, Teensy, ESP-12
//#include <RH_ASK.h>
#ifdef RH_HAVE_HARDWARE_SPI
#include <SPI.h> // Not actually used but needed to compile
#endif
#define RH_HAVE_SERIAL true;
const int BTN_UP_PIN = 3;
const int BTN_DN_PIN = 2;
int codeValue = 2;
int oldUpState = HIGH;
int oldDnState = HIGH;
//RH_ASK driver;
// RH_ASK driver(2000, 4, 5, 0); // ESP8266 or ESP32: do not use pin 11 or 2
// RH_ASK driver(2000, 3, 4, 0); // ATTiny, RX on D3 (pin 2 on attiny85) TX on D4 (pin 3 on attiny85),
void checkDnButton() {
int upState = digitalRead(BTN_UP_PIN);
if (upState != oldUpState) {
oldUpState = upState;
if (upState == LOW) {
Serial.println("Up pressed");
codeValue++;
Serial.print("Code value: ");
Serial.println(codeValue);
}
delay(20);
}
}
void checkUpButton() {
int dnState = digitalRead(BTN_DN_PIN);
if (dnState != oldDnState) {
oldDnState = dnState;
if (dnState == LOW) {
Serial.println("Down pressed");
codeValue--;
Serial.print("Code value: ");
Serial.println(codeValue);
}
delay(20);
}
}
void setup()
{
#ifdef RH_HAVE_SERIAL
Serial.begin(9600); // Debugging only
#endif
//if (!driver.init())
#ifdef RH_HAVE_SERIAL
Serial.println("init failed");
#else
;
#endif
pinMode(BTN_UP_PIN, INPUT_PULLUP);
pinMode(BTN_DN_PIN, INPUT_PULLUP);
Serial.print("Started, code value is ");
Serial.println(codeValue);
}
void loop()
{
checkDnButton();
checkUpButton();
//uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
//uint8_t buflen = sizeof(buf);
/*
if (driver.recv(buf, &buflen)) // Non-blocking
{
int i;
// Message with a good checksum received, dump it.
driver.printBuffer("Got:", buf, buflen);
}
*/
}