7 LED (3)
inta = 0;
int b = 1;
int d = 2;
int e = 3;
int f = 4;
int g = 5;
int i = 6;
int j = 7;
void setup(){
pinMode(a,OUTPUT);
pinMode(b,OUTPUT);
pinMode(d,OUTPUT);
pinMode(e,OUTPUT);
pinMode(f,OUTPUT);
pinMode(g,OUTPUT);
pinMode(i,OUTPUT);
pinMode(j,OUTPUT);
}
void loop(){
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,LOW);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
digitalWrite(i,HIGH);
digitalWrite(j,LOW);
delay(300);
seg_1.ino
int a =0;
int b = 1;
int d = 2;
int e = 3;
int f = 4;
int g = 5;
int i = 6;
int j = 7;
int c = 8;
void loop(){
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,LOW);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
digitalWrite(i,HIGH);
digitalWrite(j,LOW);
digitalWrite(c,LOW);
delay(300);
void setup(){
pinMode(a,OUTPUT);
pinMode(b,OUTPUT);
pinMode(d,OUTPUT);
pinMode(e,OUTPUT);
pinMode(f,OUTPUT);
pinMode(g,OUTPUT);
pinMode(i,OUTPUT);
pinMode(j,OUTPUT);
pinMode(c,OUTPUT);
}
7 LED ( )
_7segLED_2_pre.ino
7 LED 2(1)
int a = 0;
int b = 1;
int d = 2;
int e = 3;
int f = 4;
int g = 5;
int i = 6;
int j = 7;
int c_left = 8;
int c_right = 9;
int duration =100;
LED 0
void setup(){
pinMode(a,OUTPUT);
pinMode(b,OUTPUT);
pinMode(d,OUTPUT);
pinMode(e,OUTPUT);
pinMode(f,OUTPUT);
pinMode(g,OUTPUT);
pinMode(i,OUTPUT);
pinMode(j,OUTPUT);
pinMode(c_left,OUTPUT);
pinMode(c_right,OUTPUT);
}
void loop(){
zero_left();
delay(duration);
zero_right();
delay(duration);
}
void zero_left(){
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(d,HIGH);
_7segLED_5.ino
56.
7 LED 2(2)
int a = 0;
int b = 1;
int d = 2;
int e = 3;
int f = 4;
int g = 5;
int i = 6;
int j = 7;
int c_left = 8;
int c_right = 9;
int duration =5;
int k = 0;
void setup(){
pinMode(a,OUTPUT);
pinMode(b,OUTPUT);
pinMode(d,OUTPUT);
pinMode(e,OUTPUT);
pinMode(f,OUTPUT);
pinMode(g,OUTPUT);
pinMode(i,OUTPUT);
pinMode(j,OUTPUT);
pinMode(c_left,OUTPUT);
pinMode(c_right,OUTPUT);
}
void loop(){
for(k=1;k<100;k++){
zero_left();
delay(duration);
one_right();
delay(duration);
}
for(k=1;k<100;k++){
one_left();
delay(duration);
two_right();
delay(duration);
}
01→12→23→ _7segLED_6.ino
スケッチの例 RowColumnScanning を使用
4.外部入力による点灯位置の制御
(1)ファイル ⇒ スケッチの例 ⇒ 07.Display ⇒
RowColumnScanning を選択
(2) Arduino UNO のピン番号をLEONALD仕様に変更
// 2-dimensional array of row pin numbers:
const int row[8] = {2,7,19,5,13,18,12,16 } を
const int row[8] = {2,7,23,5,13,22,12,20 } に変更
// 2-dimensional array of column pin numbers:
const int col[8] = {6,11,10,3,17,4,8,9 } を
const int col[8] = {6,11,10,3,21,4,8,9 } に変更
21
90.
RowColumnScanning
4.外部入力による点灯位置の制御
// 2-dimensional arrayof pixels:
int pixels[8][8]; // ドットマトリクスLED用の
8×8の二次元配列を準備
// cursor position:
int x = 5; //LEDのx軸(行方向)の位置を決める変数 ⇒ pixelsのx番地
int y = 5; //LEDのy軸(列方向)の位置を決める変数 ⇒ pixelsのy番地
// initialize the pixel matrix:
for (int x = 0; x < 8; x++) {
for (int y = 0; y < 8; y++) {
pixels[x][y] = HIGH; //配列pixelsの中身をすべてHIGHに初期化
}
}
void setup( )は省略
0
1
2
3
4
5
6
7
yの番地
xの番地
0 1 2 3 4 5 6 7
22
91.
void readSensors() {
//turn off the last position:
pixels[x][y] = HIGH; // 配列pixelsの番地(x,y:前の番地)の中身をHIGHに設定
// read the sensors for X and Y values:
x = 7 - map(analogRead(A0), 0, 1023, 0, 7); //入力電圧を0~7へ変換し,
それを7から引いたものをx
y = map(analogRead(A1), 0, 1023, 0, 7); //入力電圧を0~7へ変換し,それをy
// set the new pixel position low so that the LED will turn on
// in the next screen refresh:
pixels[x][y] = LOW; // 配列pixelsの番地(x,y:現在の番地)の中身をLOWに設定
}
RowColumnScanning
4.外部入力による点灯位置の制御
A0の電圧を取得 現在の範囲 新しい範囲
0
1
2
3
4
5
6
7
yの番地
xの番地
0 1 2 3 4 5 6 7
readSensors()は,可変抵抗のつまみの位置を
電圧として読み込み,その値によって点灯位置の番
地x,y を決め,そこがONになるように配列pixelsに
LOWをセットする.
23
92.
RowColumnScanning
4.外部入力による点灯位置の制御
void refreshScreen() {//pixel[x][y]をスキャンしてLOWの位置でLEDを点灯させ,すぐに消す
// iterate over the rows (anodes):
for (int thisRow = 0; thisRow < 8; thisRow++) { // 行の繰り返し
// take the row pin (anode) high:
digitalWrite(row[thisRow], HIGH); // thisRow番目の行をHIGHにする(ONの準備)
// iterate over the cols (cathodes):
for (int thisCol = 0; thisCol < 8; thisCol++) { // 列の繰り返し
// get the state of the current pixel;
int thisPixel = pixels[thisRow][thisCol]; // thisPixel に 現在のpixels[thisRow][thisCol] の中身を代入
// when the row is HIGH and the col is LOW,
// the LED where they meet turns on:
digitalWrite(col[thisCol], thisPixel); // thisCol列 に thisPixel の値をデジタル出力
(thisPixel が LOW のところだけ LED ON)
// turn the pixel off:
if (thisPixel == LOW) { // もし thisPixel の中身が LOW ならば次を実行
digitalWrite(col[thisCol], HIGH); // thisCol列に HIGH を出力(LED OFF)
}
}
// take the row pin low to turn off the whole row:
digitalWrite(row[thisRow], LOW); // thisRow番目の行をLOWにする(OFFに戻す)
}
}
点灯
消灯
24