|
本帖最后由 motohard06 于 2013-5-19 23:05 编辑
下面程式码是一个
驱动直流马达,
读入可变电阻值用来控制直流马达转速
由PWM输出波形控控制直流马达转速
想请问如何修改上面的电路和程式码
将可变电阻改成光敏电阻,
藉由光敏电阻之光源强弱改变马达转速
零件有
马达1个
10KΩ可变电阻1个
NPN电晶体(TIP120)1个
二极体(1N4001)1个
电源
int potPin = 0; // Analog in 0 connected to the potentiometer
int transistorPin = 9; // PWM Pin 9 connected to the base of the transistor
int potValue = 0; // value returned from the potentiometer
void setup() {
// set the transistor pin as output:
pinMode(transistorPin, OUTPUT);
}
void loop() {
// read the potentiometer, convert it to 0 - 255:
potValue = analogRead(potPin) / 4;
// use that to control the transistor:
analogWrite(transistorPin, potValue);
} |
|