이전 포스팅에 이어 이번에는 LED & SWITCH Shield, FND Shield를 이용해서 입출력에 대한 제어 실습을 해보려고 합니다.
void setup() {
Serial.begin(9600);
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(9, OUTPUT);
}
void loop() {
if (digitalRead(5) == LOW) {
digitalWrite(9, 0);
Serial.println("LED1 is on");
} else if (digitalRead(6) == LOW) {
digitalWrite(9, 1);
Serial.println("LED1 is off");
}
delay(200);
}
굿 ,, 👍
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(5, INPUT);
for (int i=9; i<13; i++) {
pinMode(i, OUTPUT);
}
}
void loop() {
// default OFF 상태로 만들기
for(int i=9; i<13; i++){
digitalWrite(i, 1);
}
if (digitalRead(5) == LOW) {
for (int i=9; i<13; i++){
digitalWrite(i, 0);
Serial.print("LED ");
Serial.print(i-8);
Serial.println(" is on");
delay(200);
}
}
}
void setup() {
Serial.begin(9600);
pinMode(6, INPUT);
pinMode(7, INPUT);
for (int i=9; i<13; i++) {
pinMode(i, OUTPUT);
}
}
void loop() {
if (digitalRead(6) == LOW) {
// 1,2번 LED 켜고 3,4번 LED 끄기
digitalWrite(9,0);
digitalWrite(10,0);
digitalWrite(11,1);
digitalWrite(12,1);
} else if (digitalRead(7) == LOW) {
// 1,2번 LED 끄고 3,4번 LED 켜기
digitalWrite(9,1);
digitalWrite(10,1);
digitalWrite(11,0);
digitalWrite(12,0);
}
}
void setup() {
Serial.begin(9600);
pinMode(7, INPUT);
pinMode(8, INPUT);
for (int i=9; i<13; i++) {
pinMode(i, OUTPUT);
}
}
void loop() {
if (digitalRead(7) == LOW) {
for (int i=9; i<13; i++) {
digitalWrite(i, 0);
}
} else if (digitalRead(8) == LOW) {
for (int i=9; i<13; i++) {
digitalWrite(i, 1);
}
}
}
-> 공통 양극방식 기준으로 (음극일땐 toggle하자)
void setup() {
for (int i=5; i<13; i++) {
pinMode(i, OUTPUT);
}
}
void loop() {
for (int i=5; i<13; i++) {
digitalWrite(i, 0);
}
}
void setup() {
Serial.begin(9600);
for (int i=5; i<13; i++) {
pinMode(i, OUTPUT);
}
}
void loop() {
int num[10][4] = {
{0,0,0,0},
{0,0,0,1},
{0,0,1,0},
{0,0,1,1},
{0,1,0,0},
{0,1,0,1},
{0,1,1,0},
{0,1,1,1},
{1,0,0,0},
{1,0,0,1}
};
for (int i=0; i<10; i++) {
for (int j=0; j<4; j++) {
digitalWrite(j+5,num[i][3-j]);
digitalWrite(j+9,num[i][3-j]);
}
delay(1000);
}
}
void setup() {
for (int i=5; i<13; i++) {
pinMode(i, OUTPUT);
}
}
unsigned long fnd1, fnd2;
void loop() {
int num[10][4] = {
{0,0,0,0},
{0,0,0,1},
{0,0,1,0},
{0,0,1,1},
{0,1,0,0},
{0,1,0,1},
{0,1,1,0},
{0,1,1,1},
{1,0,0,0},
{1,0,0,1}
};
unsigned long current = round(millis());
current = int((((current+5)/10)*10)/1000);
fnd1 = current%10;
current = int(current/10);
fnd2 = current%10;
for (int i=0; i<4; i++){
digitalWrite(i+5, num[fnd1][3-i]);
digitalWrite(i+9, num[fnd2][3-i]);
}
delay(1000);
}
int num[10][4] = {
{0,0,0,0},
{0,0,0,1},
{0,0,1,0},
{0,0,1,1},
{0,1,0,0},
{0,1,0,1},
{0,1,1,0},
{0,1,1,1},
{1,0,0,0},
{1,0,0,1}
};
int fnd1, fnd2;
void setup() {
Serial.begin(9600);
for (int i=5; i<13; i++) {
pinMode(i, OUTPUT);
}
}
void loop() {
long randNum = random(0,100);
Serial.println(randNum);
fnd1 = randNum % 10;
randNum = int(randNum/10);
fnd2 = randNum % 10;
for (int i=0; i<4; i++){
digitalWrite(i+5, num[fnd1][3-i]);
digitalWrite(i+9, num[fnd2][3-i]);
}
delay(3000);
}