极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8124|回复: 0

请问一问题

[复制链接]
发表于 2013-5-19 17:07:08 | 显示全部楼层 |阅读模式
本帖最后由 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);
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-5-20 13:41 , Processed in 0.055867 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表