Paso 4: Estructura todo el código de Arduino
#include
#include "rgb_lcd.h" #include #include
rgb_lcd lcd;
const int blanco [] = {255, 255, 255}; const int rojo [] = {255, 0, 0};
const int pinRot = A0; const int pinTemp = A1; const int pinIR = A2; const int pinUV = A3;
const int pinBut = 7; const int pinBuz = 8;
const int tempref = 3975;
int statecount = 0; int tanperc = 0; int tantarg = 0; Float alltemp [8] = {0, 0, 0, 0, 0, 0, 0, 0}; flotador allIR [8] = {0, 0, 0, 0, 0, 0, 0, 0}; Float alluv [8] = {0, 0, 0, 0, 0, 0, 0, 0}; pt de int = 0; Float acctemp = 0; accIR de flotador = 0; Float accUV = 0; exposición de flotador = 0; const int displayrate = 40; const int exigencia = 170;
int maxuv = 0; maxtemp int = 0; sin firmar largo starttime = 0; endtime larga sin signo = 0;
void setup() {Serial.begin(9600), lcd.begin (16, 2); lcd.setRGB (blanco [0], blanca [1], white[2]) lcd.setCursor (0, 0); lcd.print ("Hola, soy su"); lcd.setCursor (0, 1); lcd.print ("Solmate:)" "); pinMode (pinBut, entrada); digitalWrite (pinBut, HIGH); pinMode (pinBuz, salida); statecount = 0; Delay(4000); setTan(); }
void clrRow(int row) {lcd.setCursor (fila, 0); lcd.print("");}
anular setTan() {lcd.setRGB (blanco [0], blanca [1], white[2]) lcd.setCursor (0, 0); lcd.print ("el % tan Set!"); clrRow(1); mientras (! digitalRead(pinBut)) {int rotread = analogRead(pinRot); tanperc = rotread * 100 / 1015; tantarg = rotread * exigencia / 1015; char [] perc = "100%"; int targ = tanperc; para (int me = 2; i > = 0; i--) {si (< 2 & & targ == 0) {perc [i] = ' ';} más {perc [i] = '0' + targ % 10;} targ / = 10;} lcd.setCursor (6 , 1); LCD.Print(PERC); Delay(100); } exposición = 0; mientras (digitalRead(pinBut)); LCD.Clear(); startTime = millis(); maxuv = 0; maxtemp = 0; }
readFile() Boolean {//Get el resultado de la consulta de datos de char archivo [16]; FILE * fp; FP = fopen ("/tmp/tantweet.txt", "r"); if(FP!=null) {fgets (datos, 16 fp); fclose(fp); si (datos [0] == '1') devuelve true; otra vuelta falso;} Else {devuelva false;}}
void tanned() {endtime = millis(); lcd.setRGB (rojo [0], rojo [1], red[2]); clrRow(0); clrRow(1); lcd.setCursor (0, 0); lcd.print ("perfectamente bronceada!"); digitalWrite (pinBuz, HIGH); delay(500); digitalWrite (pinBuz, bajo); delay(500); digitalWrite (pinBuz, HIGH); delay(500); digitalWrite (pinBuz, bajo); delay(500); digitalWrite (pinBuz, HIGH); delay(500); digitalWrite (pinBuz, bajo); delay(500); lcd.setRGB (blanco [0], blanca [1], white[2]); clrRow(0); lcd.setCursor (0 , 0); LCD.Print ("Tweet?"); tweet de int = 0; mientras (! digitalRead(pinBut)) {//select si o no int rotread = analogRead(pinRot); lcd.setCursor (0, 1); si (rotread < 512) {lcd.print («> Sí No "); Tweet = 1; } else {lcd.print ("sí > n"); Tweet = 0; } delay(100); } y (digitalRead(pinBut)); Si (tweet == 1) {String cmd = "python /home/root/test7.py -m"; CMD = cmd + tanperc + "-e"; CMD = cmd + ((endtime-starttime)/60000) + "-t"; CMD = cmd + maxtemp "-u"; CMD = cmd + maxuv + "> /tmp/tantweet.txt"; Excute la consulta y obtener el resultado system(cmd.buffer); LCD.Clear(); Si (readFile()) {lcd.setRGB (blanco [0], blanca [1], white[2]); lcd.clear(); lcd.setCursor (0, 0); lcd.print("Tweeted!");} else {lcd.setRGB (blanco [0], blanca [1], white[2]); lcd.clear(); lcd.setCursor (0, 0); lcd.print ("no se pudo"); lcd.setCursor (0, 1); lcd.print("tweet...");} Delay(4000); } }
void loop() {Serial.println("hello"); //check si terminado si (exposición > = tantarg) {tanned(); setTan();} else {//check si si (digitalRead(pinBut)) {mientras que (digitalRead(pinBut)); setTan();}}
actualizar los sensores entradas //temperature int tempread = analogRead(pinTemp); flotador de res = (float)(1023-tempread) * 10000/tempread; temp de flotador = 1 / (log (res/10000) /tempref+1/298.15)-273.15; Temp = temp * 1.8 + 32; acctemp += temp - alltemp [pt]; alltemp [pt] = temp; Serial.Print("Temp:"); Serial.println(Temp); Flotador de UV uv = analogRead(pinUV); UV = uv * 4980.0/1023.0 * 0.307 / 200,0; accUV += uv - alluv [pt]; alluv [pt] = ULTRAVIOLETA; Serial.Print("UV:"); Serial.println(accUV/8); PT = (pt < 7? pt + 1:0); salida datos cada 0,5 seg si (statecount % 10 == 0) {si (acctemp/8 > maxtemp) {maxtemp = (acctemp/8);} si (accUV/8 > maxuv) {maxuv = (accUV/8);} si (statecount < displayrate) {buffer de char //temperature [16], sprintf (buffer, "Temp %0.1f F", acctemp/8); clrRow(0); lcd.setCursor (2, 0); lcd.print(buffer);} más {buffer de char //UV [16], sprintf (tampón, "Índice UV %0.1f", accUV/8); clrRow(0); lcd.setCursor (2 , 0); LCD.Print(buffer); } lcd.setCursor //update tan (0, 1); para (int i = 0; i < 16 * exposición / tantarg; i ++) {lcd.print("X");}} exposición += uv/600; statecount = (statecount < 2 * displayrate? statecount + 1: 0); Delay(100); }