// Leggi il file README.md o meglio clicca sul tab Description
// accanto al tab Simulation
#include <LiquidCrystal.h>
#include "AppDataStruct.h"
// I magic number non parlano
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // RS,EN,D4,D5,D6,D7
AppData appData;
// 4 formagi
void show_attf(float att) {
bool neg = false;
if (att < 0) neg = true;
Serial.println(neg);
uint8_t u, d, c;
uint16_t u_att = fabs(att) * 10;
c = u_att / 100;
d = (u_att % 100) / 10;
u = (u_att % 10);
Serial.println(u_att);
Serial.println(c);
Serial.println(d);
Serial.println(u);
uint8_t negSize = (13 * neg) + (4 * neg);
uint8_t cifra0Size = (13 * (bool)c) + (4 * (bool)c);
uint8_t cifra1Size = 13 + 2;
uint8_t pointSize = 4 + 2;
uint8_t cifra2Size = 13;
uint8_t ws = negSize + cifra0Size + cifra1Size
+ pointSize + cifra2Size;
// punto 3 x 3 pixel
// - 6 3 . 5
// 13 + 2 + 13 + 4 + 13 + 2 + 4 + 2 + 13
/*uint8_t ws = (13 * (bool)c) + (4 * (bool)c)
+ (13 * (bool)d) + (4 * (bool)d)
+ (13 * (bool)u) + (4 * (bool)u)
+ 4 + 15;*/
/*uint8_t ws = (13 * (bool)c) + (4 * (bool)c)
+ (13 + 8) + 13 + 17; */
Serial.println(ws);
uint8_t x = 64 - (ws / 2);
Serial.println(x);
}
// -10.5 x = 30
// -9.5 x = 39
// 0.0 x = 47
void setup() {
Serial.begin(115200);
show_attf(-9.0);
// I magic number non parlano
pinMode(2, INPUT_PULLUP);
pinMode(3, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
// Le macro invece parlano al contrario dei magic number
pinMode(LED_BUILTIN, OUTPUT);
lcd.begin(16, 2);
lcd.print(" Prova riflessi ");
delay(2000);
lcd.clear();
}
void loop() {
blink();
appFunction(appData);
}