#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int incomingByte = 0;
byte crs = 0;
byte bars[8][8] =
{
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1B },
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1B, 0x1B },
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x1B, 0x1B, 0x1B },
{ 0x00, 0x00, 0x00, 0x00, 0x1B, 0x1B, 0x1B, 0x1B },
{ 0x00, 0x00, 0x00, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B },
{ 0x00, 0x00, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B },
{ 0x00, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B },
{ 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B, 0x1B },
};
const unsigned int upperThreshold = 70;
const unsigned int lowerThreshold = 50;
unsigned long lastTime = 0;
bool lastState = false;
void setup()
{
//Setup LCD
lcd.begin(16, 2);
// Special chars (bars)
for (byte bar = 0; bar < 8; bar++)
{
lcd.createChar( bar, bars[bar] );
}
//Startup display message
lcd.clear();
lcd.print("RF 433mhz sniffer");
lcd.setCursor(0, 1);
lcd.print("Avvio");
for (byte test = 0; test < 8; test++)
{
lcd.write(test);
delay(100);
}
// Setup wireless
Serial.begin(2400);
delay(500);
}
void loop()
{
if (Serial.available() > 0)
{
doubleBar();
}
incomingByte = 0;
}
void doubleBar()
{
static byte lastScaledValue = 0;
bool signalState;
unsigned int signalStabilityRange = 25;
byte vLine = 0;
incomingByte = Serial.read();
if ( incomingByte > upperThreshold || incomingByte < lowerThreshold )
{
signalState = true;
}
else
{
signalState = false;
crs = 0;
lcd.clear();
}
if (lastState != signalState)
{
lastTime = millis();
lastState = signalState;
}
if ( (millis() > lastTime + signalStabilityRange) && signalState && incomingByte < 250 )
{
lastTime = millis();
signalState = false;
lastState = false;
byte vMetter = (byte) (incomingByte / 16);
lcd.setCursor(crs + 1, 1);
lcd.print(" ");
if (vMetter < 9)
{
vLine = vMetter;
lcd.setCursor(crs, 0);
lcd.print(" ");
lcd.setCursor(crs, 1);
if (vLine > 0)
{
lcd.write(vLine - 1);
}
else
{
lcd.print(" ");
}
}
else
{
vLine = vMetter - 9;
lcd.setCursor(crs, 0);
lcd.write(vLine);
lcd.setCursor(crs, 1);
lcd.write(7);
}
crs++;
if (crs > 15)
{
crs = 0;
}
}
}