implementação da entrada analogica

Dependencies:   mbed

Fork of projeto_final by Joseanne Viana

main.cpp

Committer:
Josiii
Date:
2016-05-19
Revision:
1:57ddb7333156
Parent:
0:14a3f9fb0c13

File content as of revision 1:57ddb7333156:

#include "mbed.h"
int main(void)
{   
    Serial pc(USBTX, USBRX);
    AnalogIn ain(A0);
    DigitalOut ligaMaisPilha(PTA17);
    DigitalOut ligaMaisLed(PTA16);
    PwmOut rled(LED1);
    PwmOut gled(LED2);
    PwmOut bled(LED3);
    char msg;
    char num;
    rled=1.0f;
    gled=1.0f;
    bled=1.0f;
    int x;
  

    while(true){
        if(pc.readable()) {
            msg = pc.getc();
            num = pc.getc();
            
           x=ain.read();
         if(x < 0.4){//equivale a 3.31V  
            ligaMaisPilha=0;
            ligaMaisLed =0;
                    }
         else {
            ligaMaisPilha=1;
            ligaMaisLed= 1;
               }//else
            switch(msg){
                case 'R': //brilho
                    rled = 1.0f - float(num)/255.0;
                    break;
                case 'G':
                    gled = 1.0f - float(num)/255.0;
                    break;
                case 'B':
                    bled = 1.0f - float(num)/255.0;
                    break;
            }
        }
    }
}