Advertisement
Guest User

Untitled

a guest
Jul 20th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. int led = 10;
  2. float frequency = 440;
  3. float timeDelay = (1/frequency)*500000;
  4. String inString = "";
  5.  
  6. void setup(){
  7. Serial.begin(9600);
  8. pinMode(led, OUTPUT);
  9.  
  10.  
  11. }
  12.  
  13. void loop(){
  14. // Read serial input:
  15. while (Serial.available() > 0) {
  16. int inChar = Serial.read();
  17. if (isDigit(inChar)) {
  18. // convert the incoming byte to a char and add it to the string:
  19. inString += (char)inChar;
  20. }
  21. // if you get a newline, print the string, then the string's value:
  22. if (inChar == '\n') {
  23. frequency = inString.toInt();
  24. frequency = map(frequency,10,100,100,400);
  25. frequency = (float) frequency;
  26. timeDelay = (1/frequency)*500000;
  27. inString = "";
  28. }
  29.  
  30.  
  31.  
  32. }
  33.  
  34.  
  35.  
  36. digitalWrite(led,HIGH);
  37. delayMicroseconds(timeDelay);
  38. digitalWrite(led,LOW);
  39. delayMicroseconds(timeDelay);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement