Draw
作品簡介:
用途-此作品是用於抽誰出去買飯或買飲料。
以Arduino的LED燈代替抽籤,按一下按鈕,亮哪個LED燈便代表是誰要負責去買。而如果沒有LED燈亮的話,便代表就別買了。如果想買就再抽一次。
動機-有時候待在家常常大家都不想去買飯買飲料,所以想做一個可以抽誰要負責去買的機器
材料清單:
-Arduino 麵包板 x1
-LED燈 x6
-大按鈕 x1
-公對公電線 x15
-黃色電阻 x7
-連接線 x1
Introduction:
Usage - This machine is for people to draw about who should go out to buy food or buy drinks.
Draw is replace with the Arduino LED light. Press the button, the person's name with LED lighting up responsible for buying food or buying drinks. If no LED light up, then nobody should go and buy food and drink. If all of you want to choose a person to buy, you can take another roll.
Motivation - Sometimes when me and my family stay at home, we don't want to buy food and buy drinks, so we want to have a machine that you can take to buy.
Materials:
-Arduino breadboard x1
-LED light x6
- Large button x1
- Wire x15
- Yellow resistor x7
Connect Five LED Circuit (將LED燈的電路接好,接五個)
圖片來源:http://drho.club/2017/12/arduino-unit-2/
Connect the Button's Circuit (接按鈕的電路)
圖片來源:Arduino連接開關按鍵電路示意圖
Complete Circuit (pic) 完整電路圖
Paste the Code (貼上程式)
https://create.arduino.cc/editor/candyliu/b7c8fd93-3a14-49e1-aedc-0b671b930e19/preview
#define DEBUG 0
int first = 2; int second = 3; int third = 4; int fourth = 5; int fifth = 6; int sixth = 7; //set all LEDs
int button = 12; //button pin code int pressed = 0;
void setup() { for (int i=first; i<=sixth; i++) { pinMode(i, OUTPUT); } pinMode(button, INPUT); randomSeed(analogRead(0));
#ifdef DEBUG Serial.begin(9600); #endif
}
void buildUpTension() { for (int i=first; i<=sixth; i++) { if (i!=first) { digitalWrite(i-1, LOW); } digitalWrite(i, HIGH); delay(100); } for (int i=sixth; i>=first; i--) { if (i!=sixth) { digitalWrite(i+1, LOW); } digitalWrite(i, HIGH); delay(100); } }
void showNumber(int number) { if (number == 2) { digitalWrite(first, HIGH); } if (number == 3) { digitalWrite(second, HIGH); } if (number == 4) { digitalWrite(third, HIGH); } if (number == 5) { digitalWrite(fourth, HIGH); } if (number == 6) { digitalWrite(fifth, HIGH); } if (number == 7) { digitalWrite(sixth, HIGH); } }
int throwDice() { int randNumber = random(1,7); #ifdef DEBUG Serial.println(randNumber); #endif return randNumber; }
void loop() { pressed = digitalRead(button);
if (pressed == HIGH) { // remove previous number buildUpTension(); int thrownNumber = throwDice(); showNumber(thrownNumber); }
}