-
-
Save macaba/33813b083b226fead09bfc127f83d7a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int pulPin = 2; | |
const int enaPin = 1; | |
const int dirPin = 0; | |
float sinCounter = 0.0; | |
void setup() { | |
pinMode(pulPin, OUTPUT); | |
pinMode(dirPin, OUTPUT); | |
pinMode(enaPin, OUTPUT); | |
digitalWriteFast(enaPin, LOW); | |
digitalWriteFast(dirPin, HIGH); | |
} | |
void loop() { | |
float frequencyFloat = sinf(sinCounter) * 10.0f; | |
//float frequencyFloat = -5.5; //This line works to give a output frequency of 5. | |
int frequencyInt = abs(frequencyFloat); | |
tone(pulPin, frequencyInt); | |
Serial.println(frequencyInt); | |
sinCounter += 0.05; | |
if(sinCounter > 6.28318530718) | |
sinCounter = 0; | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment