Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Arduino PWM Speed Control:
- int E1 = 5;
- int M1 = 4;
- void setup() {
- pinMode(M1, OUTPUT);
- Serial.begin(9600);
- }
- void loop() {
- if (Serial.available()) {
- int value = Serial.parseInt();
- if (value != 0) {
- if (value > 0) {
- digitalWrite(M1, HIGH);
- } else {
- digitalWrite(M1, LOW); // Go backwards
- }
- value = abs(value);
- if (value < 5) {
- analogWrite(E1, 0);
- } else {
- value = map(value, 0, 90, 50, 255);
- analogWrite(E1, value);
- }
- delay(2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment