步驟1:零件清單
R1 = 10至220Ω?W取決于首選的LED亮度
R2,R3 = 10ΚΩ?W
Arduino Uno
霍爾傳感器
7805 5V穩(wěn)壓器TO-220
C1,C2 = 220 uf
7段LED顯示屏(共陽極)
9-12 v電池(否則連接設(shè)備
連接電線,通用PCB。
步驟2:工作原理
主要工作原理基于AVR Arduino UNO。
讀取兩個霍爾傳感器和空檔開關(guān)的信號,并將當(dāng)前檔位輸出到7段LED指示器,通過
在最大輸出功率下,傳感器和傳感器產(chǎn)生的熱量很大。或出于這個原因,我們將其直接安裝在接地層上以實現(xiàn)最大的散熱。
步驟3:電路圖
int ledPinA = 13; // LED connected to digital pin 3
int ledPinB = 12; // LED connected to digital pin 4
int ledPinC = 11; // LED connected to digital pin 5
int ledPinD = 10; // LED connected to digital pin 6
int ledPinE = 9; // LED connected to digital pin 7
int ledPinF = 8; // LED connected to digital pin 8
int ledPinG = 7; // LED connected to digital pin 9
#define BUTTON_DOWN 4
#define BUTTON_UP 6
步驟4:源代碼
#define BUTTON_DOWN 4
#define BUTTON_UP 6
int ledPinA = 13; // LED connected to digital pin 3
int ledPinB = 12; // LED connected to digital pin 4
int ledPinC = 11; // LED connected to digital pin 5
int ledPinD = 10; // LED connected to digital pin 6
int ledPinE = 9; // LED connected to digital pin 7
int ledPinF = 8; // LED connected to digital pin 8
int ledPinG = 7; // LED connected to digital pin 9
int val_down = 0;
int old_val_down = 0;
int val_up = 0;
int old_val_up = 0;
int state = 0;
int gear = 0;
// The setup() method runs once, when the sketch starts
void setup()
{
pinMode(BUTTON_DOWN, INPUT);
pinMode(BUTTON_UP, INPUT);
// initialize the digital pin as an output:
pinMode(ledPinA, OUTPUT);
pinMode(ledPinB, OUTPUT);
pinMode(ledPinC, OUTPUT);
pinMode(ledPinD, OUTPUT);
pinMode(ledPinE, OUTPUT);
pinMode(ledPinF, OUTPUT);
pinMode(ledPinG, OUTPUT);
}
void led0()
{
digitalWrite(ledPinA, LOW);
digitalWrite(ledPinB, LOW);
digitalWrite(ledPinC, LOW);
digitalWrite(ledPinD, LOW);
digitalWrite(ledPinE, LOW);
digitalWrite(ledPinF, LOW);
digitalWrite(ledPinG, HIGH);
}
void led1()
{
digitalWrite(ledPinA, HIGH);
digitalWrite(ledPinB, LOW);
digitalWrite(ledPinC, LOW);
digitalWrite(ledPinD, HIGH);
digitalWrite(ledPinE, HIGH);
digitalWrite(ledPinF, HIGH);
digitalWrite(ledPinG, HIGH);
}
void led2()
{
digitalWrite(ledPinA, LOW);
digitalWrite(ledPinB, LOW);
digitalWrite(ledPinC, HIGH);
digitalWrite(ledPinD, LOW);
digitalWrite(ledPinE, LOW);
digitalWrite(ledPinF, HIGH);
digitalWrite(ledPinG, LOW);
}
void led3()
{
digitalWrite(ledPinA, LOW);
digitalWrite(ledPinB, LOW);
digitalWrite(ledPinC, LOW);
digitalWrite(ledPinD, LOW);
digitalWrite(ledPinE, HIGH);
digitalWrite(ledPinF, HIGH);
digitalWrite(ledPinG, LOW);
}
void led4()
{
digitalWrite(ledPinA, HIGH);
digitalWrite(ledPinB, LOW);
digitalWrite(ledPinC, LOW);
digitalWrite(ledPinD, HIGH);
digitalWrite(ledPinE, HIGH);
digitalWrite(ledPinF, LOW);
digitalWrite(ledPinG, LOW);
}
void led5()
{
digitalWrite(ledPinA, LOW);
digitalWrite(ledPinB, HIGH);
digitalWrite(ledPinC, LOW);
digitalWrite(ledPinD, LOW);
digitalWrite(ledPinE, HIGH);
digitalWrite(ledPinF, LOW);
digitalWrite(ledPinG, LOW);
}
void led6()
{
digitalWrite(ledPinA, LOW);
digitalWrite(ledPinB, HIGH);
digitalWrite(ledPinC, LOW);
digitalWrite(ledPinD, LOW);
digitalWrite(ledPinE, LOW);
digitalWrite(ledPinF, LOW);
digitalWrite(ledPinG, LOW);
}
void led7()
{
digitalWrite(ledPinA, LOW);
digitalWrite(ledPinB, LOW);
digitalWrite(ledPinC, LOW);
digitalWrite(ledPinD, HIGH);
digitalWrite(ledPinE, HIGH);
digitalWrite(ledPinF, HIGH);
digitalWrite(ledPinG, HIGH);
}
void led8()
{
digitalWrite(ledPinA, LOW);
digitalWrite(ledPinB, LOW);
digitalWrite(ledPinC, LOW);
digitalWrite(ledPinD, LOW);
digitalWrite(ledPinE, LOW);
digitalWrite(ledPinF, LOW);
digitalWrite(ledPinG, LOW);
}
void led9()
{
digitalWrite(ledPinA, LOW);
digitalWrite(ledPinB, LOW);
digitalWrite(ledPinC, LOW);
digitalWrite(ledPinD, LOW);
digitalWrite(ledPinE, HIGH);
digitalWrite(ledPinF, LOW);
digitalWrite(ledPinG, LOW);
}
void setLed(int number)
{
switch (number) {
case 0:
led0();
break;
case 1:
led1();
break;
case 2:
led2();
break;
case 3:
led3();
break;
case 4:
led4();
break;
case 5:
led5();
break;
case 6:
led6();
break;
case 7:
led7();
break;
case 8:
led8();
break;
case 9:
led9();
break;
}
}
// the loop() method runs over and over again,
// as long as the Arduino has power
void oldloop()
{
// wait for a second
led0();
delay(1000); // wait for a second
led1();
delay(1000); // wait for a second
led2();
delay(1000); // wait for a second
led3();
delay(1000); // wait for a second
led4();
delay(1000); // wait for a second
led5();
delay(1000); // wait for a second
led6();
delay(1000); // wait for a second
led7();
delay(1000); // wait for a second
led8();
delay(1000); // wait for a second
led9();
delay(1000); // wait for a second
}
void loop()
{
val_up = digitalRead(BUTTON_UP);
if ((val_up == HIGH) && (old_val_up == LOW)&&gear《7 ) {
gear += 1;
delay(100);
}
old_val_up = val_up;
val_down = digitalRead(BUTTON_DOWN);
if ((val_down == HIGH) && (old_val_down == LOW)&&gear》1 ){
gear -= 1;
delay(100);
}
else if ((val_down == HIGH) && (old_val_down == LOW)&&(gear《1))
{
gear += 1;
delay(100);
}
else if ((val_down == HIGH) && (old_val_down == LOW)){
gear += -1;
delay(100);
}
old_val_down = val_down;
if (gear 》= 6) {
gear = 6;
}
setLed(gear);
}
第5步:安裝
將所有電路組裝在一起后,電路便可以正常工作并可以安裝在摩托車上了。
在我的照片中,我將這種指示器用于基于杜克自行車發(fā)動機的汽車
因此自行車的安裝技術(shù)類似。..
注意:齒輪機構(gòu)與自行車相同。
責(zé)任編輯:wv
-
指示器
+關(guān)注
關(guān)注
0文章
251瀏覽量
38276
發(fā)布評論請先 登錄
相關(guān)推薦
評論