#include <SoftwareSerial.h>
SoftwareSerial s(13,15);
#include <Wire.h>
int livello, min, max;
void setup()
{
Serial.begin(9600);
s.begin(2400);
}
void loop()
{
if (s.available() > 0)
{
static char rxBuffer[32]; // la direttiva static fa in modo che la variabile locale mantiene in memoria il valore
static int index =0;
char ch = s.read(); // Leggiamo un carattere per volta (non bloccante come parseInt())
rxBuffer[index++] = ch; // Questa istruzione aggiunge ch all'array e contemporaneamente incrementa index di 1
if (ch == '\n' )
{
// Trasmissione completa -> reset di index (ed eventualmente dell'array se necessario)
index = 0;
// conversione del char array to int con l'istruzione C sscanf
sscanf(rxBuffer, "%d;%d;%d", &livello, &min, &max);
Serial.print("Hai inviato il numero ");
Serial.println(livello);
livello = map(livello, min, max, 0, 500);
Serial.print("Risultato del map ");
Serial.println(livello);
}
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}