implementação da entrada analogica

Dependencies:   mbed

Fork of projeto_final by Guilherme Paulino

Committer:
Josiii
Date:
Thu May 19 00:31:15 2016 +0000
Revision:
1:57ddb7333156
Parent:
0:14a3f9fb0c13
coloquei a entrada analogica

Who changed what in which revision?

UserRevisionLine numberNew contents of line
guilhermepaulino 0:14a3f9fb0c13 1 #include "mbed.h"
guilhermepaulino 0:14a3f9fb0c13 2 int main(void)
guilhermepaulino 0:14a3f9fb0c13 3 {
guilhermepaulino 0:14a3f9fb0c13 4 Serial pc(USBTX, USBRX);
Josiii 1:57ddb7333156 5 AnalogIn ain(A0);
Josiii 1:57ddb7333156 6 DigitalOut ligaMaisPilha(PTA17);
Josiii 1:57ddb7333156 7 DigitalOut ligaMaisLed(PTA16);
guilhermepaulino 0:14a3f9fb0c13 8 PwmOut rled(LED1);
guilhermepaulino 0:14a3f9fb0c13 9 PwmOut gled(LED2);
guilhermepaulino 0:14a3f9fb0c13 10 PwmOut bled(LED3);
guilhermepaulino 0:14a3f9fb0c13 11 char msg;
guilhermepaulino 0:14a3f9fb0c13 12 char num;
guilhermepaulino 0:14a3f9fb0c13 13 rled=1.0f;
guilhermepaulino 0:14a3f9fb0c13 14 gled=1.0f;
guilhermepaulino 0:14a3f9fb0c13 15 bled=1.0f;
Josiii 1:57ddb7333156 16 int x;
Josiii 1:57ddb7333156 17
Josiii 1:57ddb7333156 18
guilhermepaulino 0:14a3f9fb0c13 19 while(true){
guilhermepaulino 0:14a3f9fb0c13 20 if(pc.readable()) {
guilhermepaulino 0:14a3f9fb0c13 21 msg = pc.getc();
guilhermepaulino 0:14a3f9fb0c13 22 num = pc.getc();
Josiii 1:57ddb7333156 23
Josiii 1:57ddb7333156 24 x=ain.read();
Josiii 1:57ddb7333156 25 if(x < 0.4){//equivale a 3.31V
Josiii 1:57ddb7333156 26 ligaMaisPilha=0;
Josiii 1:57ddb7333156 27 ligaMaisLed =0;
Josiii 1:57ddb7333156 28 }
Josiii 1:57ddb7333156 29 else {
Josiii 1:57ddb7333156 30 ligaMaisPilha=1;
Josiii 1:57ddb7333156 31 ligaMaisLed= 1;
Josiii 1:57ddb7333156 32 }//else
guilhermepaulino 0:14a3f9fb0c13 33 switch(msg){
guilhermepaulino 0:14a3f9fb0c13 34 case 'R': //brilho
guilhermepaulino 0:14a3f9fb0c13 35 rled = 1.0f - float(num)/255.0;
guilhermepaulino 0:14a3f9fb0c13 36 break;
guilhermepaulino 0:14a3f9fb0c13 37 case 'G':
guilhermepaulino 0:14a3f9fb0c13 38 gled = 1.0f - float(num)/255.0;
guilhermepaulino 0:14a3f9fb0c13 39 break;
guilhermepaulino 0:14a3f9fb0c13 40 case 'B':
guilhermepaulino 0:14a3f9fb0c13 41 bled = 1.0f - float(num)/255.0;
guilhermepaulino 0:14a3f9fb0c13 42 break;
guilhermepaulino 0:14a3f9fb0c13 43 }
guilhermepaulino 0:14a3f9fb0c13 44 }
guilhermepaulino 0:14a3f9fb0c13 45 }
guilhermepaulino 0:14a3f9fb0c13 46 }