Assignment 11.1

posted Aug 2, 2010, 2:33 PM by Unknown user   [ updated Aug 2, 2010, 3:12 PM ]
I turned this:
 
 
into this:
 
 
To get these:
 
So I could do this:

YouTube Video

(The tiny incandescent light was already attached to the motor as the "headlight" of the motorcycle, so I just left it on there. Also the thing jumping around is quite obviously the motor.)

Code:

const int switch1 = 4;           // Digital pin 6 connected to the push button
const int transistor1 = 9;    // connected to the base of the transistor

void setup() {
  // set  the transistor pin as output:
  pinMode(transistor1, OUTPUT);
}

void loop() {
  // turn the motor on or off based on the state of the push button
  digitalWrite(transistor1, digitalRead(switch1));
}
 
 
 
 


 

(Quick note the I used a 4 battery pack, not 2. Fritzing just didn't have a part for it and I didn't exactly find it necessary to make a new part just for the sake of adding 2 batteries.)
Comments