Diferència entre revisions de la pàgina «Calculadora Bluetooth»
Salta a la navegació
Salta a la cerca
Línia 9: | Línia 9: | ||
==Esquema== | ==Esquema== | ||
− | [[Fitxer: | + | [[Fitxer: Davidsúbeloyalento.png]] |
==Codi== | ==Codi== |
Revisió del 18:42, 23 maig 2016
Requeriments
- Placa Arduino Uno
- Bluetooth (Preferiblement HC-06)
- 7 Segment Display
- Protoboard
- 4 (Bluetooth) + 8 (7 Segment Display) cables
- Una Resistencia (3 Bandes: Taronja, Blau, Marró; Tolerància: Platejat)
Esquema
Codi
#include <SoftwareSerial.h> #define segA 2 #define segB 3 #define segC 4 #define segD 5 #define segE 6 #define segF 7 #define segG 8 SoftwareSerial BT1(0,1); void setup() { Serial.begin(9600); BT1.begin(9600); for (int i=2;i<9;i++){ pinMode(i, OUTPUT); } } void loop() { if (BT1.available()){ do{ do{ char c = BT1.read(); }while(c == NULL); if(isDigit(c)){ String S1 = String(c); int n1 = S1.toInt(); } }while(n1>10 || n1<0); do{ do{ char b = BT1.read(); }while(b == NULL); if(isDigit(b)){ String S2 = String(b); int n2 = S2.toInt(); } }while(n2>10 || n2<0); int resultat = n1 + n2; switch(resultat){ case 0: digitalWrite(segA, HIGH); digitalWrite(segB, HIGH); digitalWrite(segC, HIGH); digitalWrite(segD, HIGH); digitalWrite(segE, HIGH); digitalWrite(segF, HIGH); digitalWrite(segG, LOW); break; case 1: digitalWrite(segA, LOW); digitalWrite(segB, HIGH); digitalWrite(segC, HIGH); digitalWrite(segD, LOW); digitalWrite(segE, LOW); digitalWrite(segF, LOW); digitalWrite(segG, LOW); break; case 2: digitalWrite(segA, HIGH); digitalWrite(segB, HIGH); digitalWrite(segC, LOW); digitalWrite(segD, HIGH); digitalWrite(segE, HIGH); digitalWrite(segF, LOW); digitalWrite(segG, HIGH); break; case 3: digitalWrite(segA, HIGH); digitalWrite(segB, HIGH); digitalWrite(segC, HIGH); digitalWrite(segD, HIGH); digitalWrite(segE, LOW); digitalWrite(segF, LOW); digitalWrite(segG, HIGH); break; case 4: digitalWrite(segA, LOW); digitalWrite(segB, HIGH); digitalWrite(segC, HIGH); digitalWrite(segD, LOW); digitalWrite(segE, LOW); digitalWrite(segF, HIGH); digitalWrite(segG, HIGH); break; case 5: digitalWrite(segA, HIGH); digitalWrite(segB, LOW); digitalWrite(segC, HIGH); digitalWrite(segD, HIGH); digitalWrite(segE, LOW); digitalWrite(segF, HIGH); digitalWrite(segG, HIGH); break; case 6: digitalWrite(segA, HIGH); digitalWrite(segB, LOW); digitalWrite(segC, HIGH); digitalWrite(segD, HIGH); digitalWrite(segE, HIGH); digitalWrite(segF, HIGH); digitalWrite(segG, HIGH); break; case 7: digitalWrite(segA, HIGH); digitalWrite(segB, HIGH); digitalWrite(segC, HIGH); digitalWrite(segD, LOW); digitalWrite(segE, LOW); digitalWrite(segF, LOW); digitalWrite(segG, LOW); break; case 8: digitalWrite(segA, HIGH); digitalWrite(segB, HIGH); digitalWrite(segC, HIGH); digitalWrite(segD, HIGH); digitalWrite(segE, HIGH); digitalWrite(segF, HIGH); digitalWrite(segG, HIGH); break; case 9: digitalWrite(segA, HIGH); digitalWrite(segB, HIGH); digitalWrite(segC, HIGH); digitalWrite(segD, HIGH); digitalWrite(segE, LOW); digitalWrite(segF, HIGH); digitalWrite(segG, HIGH); break; defaul: Serial.write("Error, el resultat ha de trobar-se entre 0-9"); break; } } delay(200); }