Created
September 24, 2018 14:40
-
-
Save jenschr/43c7f3f78df952323d0bfec6154aacff to your computer and use it in GitHub Desktop.
TIP120 motor control
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
////////////////////////////////////////////////////////////////// | |
//©2011 bildr | |
//Released under the MIT License – Please reuse change and share | |
//Simple code to output a PWM sine wave signal on pin 9 | |
////////////////////////////////////////////////////////////////// | |
#define fadePin 9 | |
void setup(){ | |
pinMode(fadePin, OUTPUT); | |
} | |
void loop(){ | |
for(int i = 0; i<360; i++){ | |
//convert 0-360 angle to radian (needed for sin function) | |
float rad = DEG_TO_RAD * i; | |
//calculate sin of angle as number between 0 and 255 | |
int sinOut = constrain((sin(rad) * 128) + 128, 0, 255); | |
analogWrite(fadePin, sinOut); | |
delay(15); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment