Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <TEA5767Radio.h>
- #define CLK 2
- #define DT 3
- #define SW 4
- TEA5767Radio radio = TEA5767Radio();
- float counter = 107.7;
- int currentStateCLK;
- int lastStateCLK;
- String currentDir ="";
- unsigned long lastButtonPress = 0;
- void setup()
- {
- pinMode(CLK,INPUT);
- pinMode(DT,INPUT);
- pinMode(SW, INPUT_PULLUP);
- lastStateCLK = digitalRead(CLK);
- Serial.begin(9600);
- Serial.print(" Frecvency: ");
- Serial.println(counter);
- Wire.begin();
- radio.setFrequency(107.7);
- }
- void loop()
- {
- currentStateCLK = digitalRead(CLK);
- if (currentStateCLK != lastStateCLK && currentStateCLK == 1)
- {
- if (digitalRead(DT) != currentStateCLK)
- {
- counter = counter + 0.1;
- if (counter > 108.1)
- {
- counter = 87.5;
- }
- currentDir ="UP";
- radio.setFrequency(counter);
- } else
- {
- counter = counter - 0.1;
- if (counter < 87.5)
- {
- counter = 108;
- }
- currentDir ="DOWN";
- radio.setFrequency(counter);
- }
- Serial.print("Direction: ");
- Serial.print(currentDir);
- Serial.print(" - Frecvency: ");
- Serial.println(counter);
- }
- lastStateCLK = currentStateCLK;
- int btnState = digitalRead(SW);
- if (btnState == LOW)
- {
- if (millis() - lastButtonPress > 50)
- {
- Serial.println("Button pressed!");
- }
- lastButtonPress = millis();
- }
- delay(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement