Buzzer com LDR, LED e PWM

Dependencies:   mbed

Committer:
guilhermepaulino
Date:
Mon May 16 18:17:30 2016 +0000
Revision:
0:e7d459325c12
Desafio de buzzer com LDR, LED vermelho e PWM

Who changed what in which revision?

UserRevisionLine numberNew contents of line
guilhermepaulino 0:e7d459325c12 1 #include "mbed.h"
guilhermepaulino 0:e7d459325c12 2 AnalogIn ain(A0);
guilhermepaulino 0:e7d459325c12 3 DigitalOut buzzer(PTA17);
guilhermepaulino 0:e7d459325c12 4 PwmOut ledr(LED1); // LED vermelho
guilhermepaulino 0:e7d459325c12 5 int x;
guilhermepaulino 0:e7d459325c12 6 int main(){
guilhermepaulino 0:e7d459325c12 7 while(1){
guilhermepaulino 0:e7d459325c12 8 x=ain.read();
guilhermepaulino 0:e7d459325c12 9 if(x < 0.4){
guilhermepaulino 0:e7d459325c12 10 buzzer=0;
guilhermepaulino 0:e7d459325c12 11 ledr=1.0f;
guilhermepaulino 0:e7d459325c12 12 }
guilhermepaulino 0:e7d459325c12 13 else {
guilhermepaulino 0:e7d459325c12 14 buzzer=1;
guilhermepaulino 0:e7d459325c12 15 //ledr=0.0f;
guilhermepaulino 0:e7d459325c12 16 for(float p=0.0f; p < 1.0f; p += 0.01f){
guilhermepaulino 0:e7d459325c12 17 ledr=p;
guilhermepaulino 0:e7d459325c12 18 wait(0.02);
guilhermepaulino 0:e7d459325c12 19 }
guilhermepaulino 0:e7d459325c12 20 }
guilhermepaulino 0:e7d459325c12 21 }
guilhermepaulino 0:e7d459325c12 22 }