Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int led = 10;
- float frequency = 440;
- float timeDelay = (1/frequency)*500000;
- String inString = "";
- void setup(){
- Serial.begin(9600);
- pinMode(led, OUTPUT);
- }
- void loop(){
- // Read serial input:
- while (Serial.available() > 0) {
- int inChar = Serial.read();
- if (isDigit(inChar)) {
- // convert the incoming byte to a char and add it to the string:
- inString += (char)inChar;
- }
- // if you get a newline, print the string, then the string's value:
- if (inChar == '\n') {
- frequency = inString.toInt();
- frequency = map(frequency,10,100,100,400);
- frequency = (float) frequency;
- timeDelay = (1/frequency)*500000;
- inString = "";
- }
- }
- digitalWrite(led,HIGH);
- delayMicroseconds(timeDelay);
- digitalWrite(led,LOW);
- delayMicroseconds(timeDelay);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement