|
站長Blog文章單元 -
小專案(Project,適合入門到中型專案作品)
|
|
作者是 ken
|
|
週二, 11 十月 2011 03:22 |
|

難度:LV5
類別:擴充IC + Arduino應用
包含範圍:七段顯示器+ Maxim 7219 + Arduino + 按鈕控制
使用零件:七段顯示器 x 2, max7219 x 1, arduino x 1, 無段開關 x 1, 電池 AA x 3, 電池盒, 木作外盒, 壓克力雷射切割
完成影片:
電路:
程式碼:
#include "LedControl.h"
// pin 12 is connected to the DataIn
// pin 11 is connected to the CLK
// pin 10 is connected to LOAD
LedControl lc=LedControl(8,10,9,1);
long randNumber1;
long randNumber2;
unsigned long delaytime=10;
int get=0;
int zero = 0;
char mc;
int m =0;
int index =0;
int max1 = 5;
int min0 = 2;
void setup() {
lc.shutdown(0,false);
lc.setIntensity(0,8);
lc.clearDisplay(0);
randomSeed(analogRead(0));
randomSeed(analogRead(1));
Serial.begin(9600);
pinMode(2,INPUT);
pinMode(13,OUTPUT);
m = max1 + min0;
lc.setChar(0,0,'0',false);
lc.setChar(0,1,'0',false);
}
void get0Segment(int x) {
//for(int i=0;i<10;i++){
lc.setChar(0,1,(char)x,false);
//delay(delaytime);
//}
}
void get10Segment(int y) {
//for(int i=0;i<10;i++){
lc.setChar(0,0,(char)y,false);
//delay(delaytime);
//}
}
void loop() {
digitalWrite(13,HIGH);
get = digitalRead(2);
randNumber1 = random(0,10);
randNumber2 = random(0,max1+1);
Serial.println(get);
//Serial.println(randNumber1);
if(get == 0){
if(index >= 0 && index < 200){
mix();
}else{
index =0;
}
}
delay(delaytime);
digitalWrite(13,LOW);
}
void mix(){
index++;
zero = randNumber1 + randNumber2;
if(zero != 0 ){
get0Segment(randNumber1);
get10Segment(randNumber2);
}
}
|
|
最近更新在 週二, 11 十月 2011 03:38 |