]> git.piffa.net Git - sketchbook_andrea/blob - motors/simple_motor_PWM_transistor_diode_1/simple_motor_PWM_transistor_diode_1.ino
ac23845a35d33fff9a08f8a51808000cbe235dc0
[sketchbook_andrea] / motors / simple_motor_PWM_transistor_diode_1 / simple_motor_PWM_transistor_diode_1.ino
1 /* Simple Motor
2  This sketch use a transistor and a diode
3  in order to poer a 5v ~150mAh directly from the board.
4  Hard thing is to find a suitable motor!
5
6  This version uses PWM for acceleration / deceleration
7  */
8
9 int motorPin = 9;
10 void setup() {
11   pinMode(motorPin, OUTPUT);
12 }
13 void loop() {
14   for(int motorValue = 0 ; motorValue <= 255; motorValue +=5){ // PWM up
15     analogWrite(motorPin, motorValue);
16     delay(60);
17   }
18   for(int motorValue = 255 ; motorValue >= 0; motorValue -=5){ // PWM down
19     analogWrite(motorPin, motorValue);
20     delay(30);
21   }
22 delay(900); // Pause 
23 }
24
25
26
27