Ein Transistor wird benutzt, um zwei LEDs an- und auszuschalten.
/*
* MOSFET IRF630 (metal oxide semiconductor field-effect transistor)
* controls motor (using external power) with a potentiometer
* more info: http://itp.nyu.edu/physcomp/Tutorials/HighCurrentLoads
*/
int transistorPin = 9; // connected to the base of the transistor
int potPin = 0; // choose pin for the potentiometer
void setup() {
pinMode(transistorPin, OUTPUT); // set the transistor pin as output:
}
void loop() {
int sensorValue = analogRead(potPin); // read the potentiometer
sensorValue = map(sensorValue, 0, 1023, 0, 255); // map the sensor value to a range from 0 - 255
analogWrite(transistorPin, sensorValue); // use that to control the transistor
}
Dieses Beispiel herunterladen
