Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //http://labdegaragem.com/forum/topics/convertendo-valores-e-jogando-no-lcd
- #include <LiquidCrystal.h>
- #include <TimerOne.h>
- #define botao_incremento A0
- #define botao_decremento A1
- #define botao_frequencia_incremento A2
- #define botao_frequencia_decremento A3
- unsigned long freq;
- float dspduty;
- unsigned int duty;
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- // ------------------------------------ setup -------------------------------
- void setup()
- {
- Serial.begin(9600);
- lcd.begin(16,2);
- lcd.print("BEM VINDOS");
- pinMode(A0, INPUT);
- pinMode(A1, INPUT);
- pinMode(A2, INPUT);
- pinMode(A3, INPUT);
- pinMode(9, OUTPUT);
- }
- // ---------------------------------- map floating ------------------------
- float map_double(double x, double in_min, double in_max, double out_min, double out_max)
- {
- return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
- }
- // ------------------------------------ loop -------------------------------
- void loop()
- {
- lcd.print (" ");
- lcd.setCursor(0,1);
- Timer1.initialize(freq);
- Timer1.pwm(9, duty);
- delay(100);
- if(digitalRead(botao_frequencia_incremento) == HIGH)
- {
- freq = freq +1000;
- // Serial.println(freq);
- delay(500);
- }
- if(digitalRead(botao_frequencia_decremento)== HIGH)
- {
- freq = freq -1000;
- // Serial.println(freq);
- delay(500);
- }
- lcd.print (" ");
- lcd.setCursor(0,1);
- if(digitalRead(botao_incremento) == HIGH)
- {
- duty = duty +500;
- delay(500);
- }
- if(digitalRead(botao_decremento) == HIGH)
- {
- duty = duty -500;
- delay(500);
- }
- // Serial.println(duty);
- // dspduty = map(duty,0 ,1023,0, 100);
- dspduty = map_double(duty,0 ,1023,0, 100);
- Serial.println(dspduty,1);
- lcd.print(dspduty);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement