Skip to content

Instantly share code, notes, and snippets.

@jenschr
Created September 24, 2018 14:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jenschr/43c7f3f78df952323d0bfec6154aacff to your computer and use it in GitHub Desktop.
Save jenschr/43c7f3f78df952323d0bfec6154aacff to your computer and use it in GitHub Desktop.
TIP120 motor control
//////////////////////////////////////////////////////////////////
//©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