Created
March 25, 2017 16:17
-
-
Save jonathanprozzi/be56948a8b7aa24ae0f105a7cf73b3db 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
/* | |
This sketch is from the Adafruit Arduino series by Simon Monk. | |
Additional comments added by Jonathan Prozzi. | |
Adafruit Arduino - Lesson 13. DC Motor | |
*/ | |
int motorPin = 3; // set the pin that controls the motor. this is the one that attachs to the resistor | |
void setup() | |
{ | |
pinMode(motorPin, OUTPUT); | |
Serial.begin(9600); // open the serial monitor so that you can input the speed value | |
while (! Serial); | |
Serial.println("Speed 0 to 255"); | |
} | |
void loop() | |
{ | |
if (Serial.available()) // as long as the Serial monitor is available, enter the motor speed | |
{ | |
int speed = Serial.parseInt(); | |
if (speed >= 0 && speed <= 255) // check to make sure that the value entered falls in the actual range | |
{ | |
analogWrite(motorPin, speed); // this writes the speed value to the motor, causing it to rotate | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment