嘿,伙计们。今天我经过一个信号灯时,我看到旁边有个计数器,所以我想用Arduino创建一个自己的计数器。于是就创建这个简易的计数器。
步骤1:需要的组件:
需要的组件是:
arduino
电阻器- 220Ω。
7段LED。
跳线。
面包板
让我们开始接口。
步骤2:增加220欧姆电阻:
如图所示,7段led被放置在配电板上。这里我们要添加220欧姆的电阻。顶端和底端中间引脚是普通引脚。我们需要把这个引脚连接到电阻上,如图所示。
步骤3:连接剩余引脚:
连接的其余引脚如下:
顶部引脚(从左侧)第一引脚到数字引脚8
第二引脚到数字引脚9
第三针到电阻器
第四针数字插针7
第五针数字插针6
底销(从左侧)
第一引脚到数字引脚10
第二引脚到数字Pin 11
第三针到电阻器
第四针数字插针12
第五针数字插针3
让我们开始编码。
第四步:烧录代码:
int c = 12;
int d = 11;
int e = 10;
int g = 9;
int f = 8;
int a = 7;
int b = 6;
int chrono = 1000;
void zero(){
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, HIGH); }
void one(){
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(g, HIGH);
digitalWrite(f, HIGH);
digitalWrite(a, HIGH);
digitalWrite(b, LOW); }
void two(){
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(g, LOW);
digitalWrite(f, HIGH);
digitalWrite(a, LOW);
digitalWrite(b, LOW); }
void three(){
digitalWrite(c, LOW);
digitalWrite(d, LOW)
; digitalWrite(e, HIGH);
digitalWrite(g, LOW);
digitalWrite(f, HIGH);
digitalWrite(a, LOW);
digitalWrite(b, LOW); }
void four(){
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(g, LOW);
digitalWrite(f, LOW);
digitalWrite(a, HIGH);
digitalWrite(b, LOW); }
void five(){
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, LOW); }
void six(){
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW); }
void seven(){
digitalWrite(a, LOW);
digitalWrite(b, LOW)
; digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
}
void eight(){
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(g, LOW);
digitalWrite(f, LOW);
digitalWrite(a, LOW);
digitalWrite(b, LOW); }
void nine(){
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, LOW); }
void setup() {
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(g, OUTPUT);
pinMode(f, OUTPUT);
pinMode(a, OUTPUT);
pinMode(b, OUTPUT); }
void loop() {
zero();
delay(chrono);
one();
delay(chrono);
two();
delay(chrono);
three();
delay(chrono);
four();
delay(chrono);
five();
delay(chrono);
six();
delay(chrono);
seven();
delay(chrono);
eight();
delay(chrono);
nine();
delay(chrono);
}