用arduino模拟NE5555

创意展示、DIY分享、经验交流
回复
头像
shaoziyang
帖子: 3917
注册时间: 2019年 10月 21日 13:48

用arduino模拟NE5555

#1

帖子 shaoziyang »

用arduino模拟经典的NE555定时器

图片

程序

代码: 全选

int npn=12;
int out=6;
void setup() {
Serial.begin(9600);
pinMode(npn,OUTPUT);
pinMode(out,OUTPUT);
}

bool comp1,comp2;
void loop() {
int x=analogRead(A0);//reading the voltage at the treshold and trigger pins
int y=analogRead(A1);
float trig=x*5/1023;
float tres=y*5/1023;
Serial.print("trig=");
Serial.println(trig);
Serial.print("tres=");
Serial.println(tres);
if (trig>=5/3){//comparator1
comp2=false;
}
else{
comp2=true;
}
if (tres>=10/3){//comparator2
comp1=true;
}
else{
comp1=false;
}
if (comp1==true && comp2==false){//flip flop
digitalWrite(npn,HIGH);
digitalWrite(out,LOW);
}
if (comp1==false && comp2==true){
digitalWrite(npn,LOW);
digitalWrite(out,HIGH);
}

}
https://www.hackster.io/dincabogdan2005 ... 555-415c2a
 

回复

  • 随机主题
    回复总数
    阅读次数
    最新文章