Diferència entre revisions de la pàgina «Calculadora Bluetooth»
Salta a la navegació
Salta a la cerca
(→Codi) |
|||
Línia 11: | Línia 11: | ||
[[Fitxer: Davidsúbeloyalento.png]] | [[Fitxer: Davidsúbeloyalento.png]] | ||
− | |||
<pre>#include <SoftwareSerial.h> | <pre>#include <SoftwareSerial.h> | ||
#define segA 2 | #define segA 2 | ||
Línia 23: | Línia 22: | ||
SoftwareSerial BT1(0,1); | SoftwareSerial BT1(0,1); | ||
− | void setup() | + | void setup(){ |
− | |||
− | |||
− | |||
− | + | Serial.begin(9600); | |
− | + | BT1.begin(9600); | |
− | |||
− | |||
− | void loop() | + | for (int i=2;i<9;i++){ |
− | + | pinMode(i, OUTPUT); | |
− | + | } | |
+ | } | ||
+ | |||
+ | void loop(){ | ||
+ | |||
+ | char c; | ||
+ | char b; | ||
+ | int n1; | ||
+ | int n2; | ||
+ | int resultat; | ||
+ | |||
+ | if (BT1.available()){ | ||
do{ | do{ | ||
do{ | do{ | ||
− | + | c = BT1.read(); | |
}while(c == NULL); | }while(c == NULL); | ||
if(isDigit(c)){ | if(isDigit(c)){ | ||
String S1 = String(c); | String S1 = String(c); | ||
− | + | n1 = S1.toInt(); | |
} | } | ||
Línia 52: | Línia 57: | ||
do{ | do{ | ||
− | + | b = BT1.read(); | |
}while(b == NULL); | }while(b == NULL); | ||
if(isDigit(b)){ | if(isDigit(b)){ | ||
String S2 = String(b); | String S2 = String(b); | ||
− | + | n2 = S2.toInt(); | |
} | } | ||
}while(n2>10 || n2<0); | }while(n2>10 || n2<0); | ||
− | + | resultat = n1 + n2; | |
switch(resultat){ | switch(resultat){ | ||
Línia 173: | Línia 178: | ||
delay(200); | delay(200); | ||
− | + | } | |
+ | </pre> | ||
==Imatges== | ==Imatges== | ||
[[Fitxer:display.png]] | [[Fitxer:display.png]] |
Revisió del 18:52, 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: Or)
Esquema
#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(){ char c; char b; int n1; int n2; int resultat; if (BT1.available()){ do{ do{ c = BT1.read(); }while(c == NULL); if(isDigit(c)){ String S1 = String(c); n1 = S1.toInt(); } }while(n1>10 || n1<0); do{ do{ b = BT1.read(); }while(b == NULL); if(isDigit(b)){ String S2 = String(b); n2 = S2.toInt(); } }while(n2>10 || n2<0); 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); }