Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void loop() {
- if(Serial.available()>0){
- int value = Serial.read()-'0'; //e um sistema binário em que o valor indicado influencia duty-cycle, 0- e o valor previsto, 1- e o valor subtraído por 10.
- dutyCycle=value*10; // o duty é em percentagem
- Serial.println(dutyCycle);
- }
- cicloonoffwithdelay(1000,dutyCycle);
- }
- //Esta função gera uma onda quadrada
- //Parâmetros: A frequência e o dutycycle da onda
- void cicloonoffwithdelay(int frequency, int dutyCycle) { //usamos o ciclo com delay ao contrário da pergunta 13
- long T;
- T=1000000/frequency;
- long Ton;
- Ton=dutyCycle*T/100;
- long Toff=T-Ton;
- digitalWrite(pin, HIGH);
- delayMicroseconds(Ton);
- digitalWrite(pin, LOW);
- delayMicroseconds(Toff);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement