랜덤으로 30개의 숫자를 만들고 짝수일때 빨간 홀수일때 블루
//----------$ Pin & Variable setting $-----------------
const int led_Red_pin = 13;
const int led_Blue_pin = 12;
const int switch_button_pin = 11;
int index;
int number;
int sum_Even = 0;
int sum_Odd = 0;
//--------------------------------------------
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(led_Red_pin, OUTPUT); // Red : 13
pinMode(led_Blue_pin, OUTPUT); // Blue: 12
pinMode(switch_button_pin, INPUT); // switch: 11
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(switch_button_pin)) {//---------> $ [case1 switch ON!!] $
for (index= 1; index<= 30; index++) {
number = rand()%30 +1 ;
digitalWrite(led_Red_pin, LOW);//-----> [Red OFF]
digitalWrite(led_Blue_pin, LOW);//---> [Blue OFF]
if (number%2 == 0) { // ----------------------> [ number is even_number ]
Serial.println(number);
sum_Even += number;
digitalWrite(led_Red_pin, HIGH);//-----> [Red ON]
delay(1000);//-----------------------------> [1 second delay ]
} else { // ----------------------------------------> [ number is odd_number ]
Serial.println(number);
sum_Odd += number;
digitalWrite(led_Blue_pin , HIGH);//---> [Blue ON]
delay(1000);//-----------------------------> [1 second delay ]
}
}
Serial.println(sum_Even);
Serial.println(sum_Odd);
} else {//-------------------------------------------> $ [case2 switch OFF!!] $
digitalWrite(led_Red_pin, LOW);//-----> [Red OFF]
digitalWrite(led_Blue_pin, LOW);//----> [Blue OFF]
}
}
'arduino_' 카테고리의 다른 글
illumination_sensor (조도센서) (0) | 2016.02.13 |
---|---|
아놀로그 핀 디지털 핀으로 대체 가능함 (0) | 2016.02.13 |
(smart toilet) 논문 (0) | 2016.01.13 |
조도센서---> led_Green (0) | 2015.09.08 |
Random_led_four (0) | 2015.08.24 |
(smart toilet) 논문
https://www.youtube.com/watch?v=ugbl0RBU5bo
일부 공개
#include <Wire.h>
const int fnd_a1 = 2;
const int fnd_a2 = 14;
int k=0;
int count=1;
int i=1;
int result = 0;
int n = 0;
const int trig_pin = 22;
const int echo_pin = 23;
const int led_pin = 29;
unsigned char table1[10][8] =
{
//h,g,f,e,d,c,b,a
{1,0,1,1,1,1,1,1},//0
{1,0,0,0,0,1,1,0},//1
{1,1,0,1,1,0,1,1},//2
{1,1,0,0,1,1,1,1},//3
{1,1,1,0,0,1,1,0},//4
{1,1,1,0,1,1,0,1},//5
{1,1,1,1,1,1,0,1},//6
{1,0,0,0,0,1,1,1},//7
{1,1,1,1,1,1,1,1},//8
{1,1,1,0,1,1,1,1}//9
};
unsigned char table2[10][8] =
{
//h,g,f,e,d,c,b,a
{0,0,1,1,1,1,1,1},//0
{0,0,0,0,0,1,1,0},//1
{0,1,0,1,1,0,1,1},//2
{0,1,0,0,1,1,1,1},//3
{0,1,1,0,0,1,1,0},//4
{0,1,1,0,1,1,0,1},//5
{0,1,1,1,1,1,0,1},//6
{0,0,0,0,0,1,1,1},//7
{0,1,1,1,1,1,1,1},//8
{0,1,1,0,1,1,1,1}//9
};
void setup() {
// put your setup code here, to run once:
//seven segment1
Wire.begin(); //i2c 버스에 참여
Serial.begin(9600); // 직렬 통신 초기화
for(int i=fnd_a1; i<fnd_a1+8; i++)
{
pinMode(i, OUTPUT);
}
//seven segment2
for(int j=fnd_a2; j<fnd_a2+8; j++)
{
pinMode(j, OUTPUT);
}
//0
for(int j=0; j<8; j++){//a~g
digitalWrite(fnd_a1 + j, table1[0][7-j]);
}
//0
for(int j=0; j<8; j++){//a~g
digitalWrite(fnd_a2 + j, table2[0][7-j]);
}
pinMode(trig_pin, OUTPUT);
pinMode(echo_pin, INPUT);
pinMode(led_pin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(trig_pin, LOW);
delayMicroseconds(2);
digitalWrite(trig_pin, HIGH);
delayMicroseconds(10);
digitalWrite(trig_pin, LOW);
long distance = pulseIn(echo_pin, HIGH)/58.2;
Serial.println(distance);
if(distance <60)
{
n = 1;
for(int j=0; j<8; j++)
{
if(i==10)
{
for(int s=0; s<8; s++)
{
digitalWrite(fnd_a2 + s, table2[k][7-s]);
}
i = 0;
}
else
{
digitalWrite(fnd_a1 + j, table1[i][7-j]);
if(i==1 && k==0)
{
digitalWrite(led_pin, HIGH);
}
}
}
delay(300);
digitalWrite(led_pin, LOW);
count++;
i++;
//Serial.println("count");
if(count == 10)
{
k++;
count = 0;
if(k>9)
{
k = 0;
}
}
}
else//
{
Wire.requestFrom(5,1);//slave 5에게 1byte 요구
while(Wire.available())
{
long c = Wire.read();
Serial.println(c);
delay(300);
if(c != 0 && n ==0)
{
if( i == 0)
{
for(int j=0; j<8; j++)
{
digitalWrite(fnd_a1 + j, table1[9][7-j]);
}
if(k!=0)
{
k -= 1;
for(int j=0; j<8; j++)
{
digitalWrite(fnd_a2 + j, table2[k][7-j]);
}
}
i= 9;
count = 9;
}
else
{
i -=1;
count -=1;
for(int j=0; j<8; j++)
{
digitalWrite(fnd_a1 + j, table1[i][7-j]);
}
}
}
}
}
n = 0;
}
'arduino_' 카테고리의 다른 글
아놀로그 핀 디지털 핀으로 대체 가능함 (0) | 2016.02.13 |
---|---|
랜덤으로 30개의 숫자를 만들고 짝수일때 빨간 홀수일때 블루 (0) | 2016.02.13 |
조도센서---> led_Green (0) | 2015.09.08 |
Random_led_four (0) | 2015.08.24 |
기초1(switch(1)-> led(on), switch(2)-> led(off) (0) | 2015.08.24 |
조도센서---> led_Green
void setup() {
// put your setup code here, to run once:
pinMode(13, HIGH);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int value = analogRead(A0);
Serial.println(value);
delay(100);
if(value >=100)
{
digitalWrite(13, HIGH);
delay(1000);
}
else
{
digitalWrite(13, LOW);
delay(1000);
}
}
'arduino_' 카테고리의 다른 글
랜덤으로 30개의 숫자를 만들고 짝수일때 빨간 홀수일때 블루 (0) | 2016.02.13 |
---|---|
(smart toilet) 논문 (0) | 2016.01.13 |
Random_led_four (0) | 2015.08.24 |
기초1(switch(1)-> led(on), switch(2)-> led(off) (0) | 2015.08.24 |
기초(switch(ON)-> LED(ON), switch(OFF)-> LED(OFF)) (0) | 2015.08.24 |
Random_led_four
const int ledRed = 13;
const int ledGreen = 12;
const int ledYellow = 11;
const int ledBlue = 10;
int a;
void setup() {
// put your setup code here, to run once:
pinMode(ledRed, OUTPUT);
pinMode(ledBlue , OUTPUT);
pinMode(ledGreen, OUTPUT);
pinMode(ledYellow, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
a = rand()%4;
Serial.println(a);
if(a == 0)//ledRed ON
{
digitalWrite(ledBlue, LOW);
digitalWrite(ledGreen, LOW);
digitalWrite(ledYellow, LOW);
digitalWrite(ledRed , HIGH);
delay(1000);//1초
}
else if(a == 1)//ledBlue ON
{
digitalWrite(ledRed, LOW);
digitalWrite(ledGreen, LOW);
digitalWrite(ledYellow, LOW);
digitalWrite(ledBlue , HIGH);
delay(1000);//1초
}
else if(a == 2)//ledGreen ON
{
digitalWrite(ledRed, LOW);
digitalWrite(ledBlue, LOW);
digitalWrite(ledYellow, LOW);
digitalWrite(ledGreen , HIGH);
delay(1000);//1초
}
else//ledYellow ON
{
digitalWrite(ledRed, LOW);
digitalWrite(ledBlue, LOW);
digitalWrite(ledGreen, LOW);
digitalWrite(ledYellow , HIGH);
delay(1000);//1초
}
}
'arduino_' 카테고리의 다른 글
(smart toilet) 논문 (0) | 2016.01.13 |
---|---|
조도센서---> led_Green (0) | 2015.09.08 |
기초1(switch(1)-> led(on), switch(2)-> led(off) (0) | 2015.08.24 |
기초(switch(ON)-> LED(ON), switch(OFF)-> LED(OFF)) (0) | 2015.08.24 |
arduino_Ultra_seven_segment_count (0) | 2015.08.24 |
기초1(switch(1)-> led(on), switch(2)-> led(off)
const int switchPin_1 = 11;//LED ON!!!
const int switchPin_2 = 9;//LED OFF!!
const int ledRed = 13;
int result_1;
int result_2;
void setup() {
// put your setup code here, to run once:
pinMode(ledRed, OUTPUT);
pinMode(switchPin_1, INPUT);
pinMode(switchPin_2, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
result_1 = digitalRead(switchPin_1);
result_2 = digitalRead(switchPin_2);
if(result_1 == HIGH)
{
digitalWrite(ledRed, HIGH);
}
if(result_2 == HIGH)
{
digitalWrite(ledRed, LOW);
}
}
ver 2 2016.1----------------------------------------------------------------------------------------------------------------------
#define TURN_ON 1
#define TURN_OFF 0
const int button_turn_on_pin = 12;
const int button_turn_off_pin = 11;
const int ledRed_pin = 10;
int count = 0;
int button_on;
int button_off;
void setup() {
// put your setup code here, to run once:
pinMode(12, INPUT); //button_turn_on_pin
pinMode(11, INPUT); //button_turn_off_pin
pinMode(10, OUTPUT); //ledRed_pin
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
button_on = digitalRead(12);
button_off = digitalRead(11);
//BUTTON_ON)
if(button_on == TURN_ON)
{
if(count == 0){
Serial.println("ledRed_pin is turn on");
count = 1;
}
digitalWrite(ledRed_pin, HIGH);
}
//BUTTON_OFF)
if(button_off == TURN_ON)
{
button_on = TURN_OFF;
if(count == 1){
Serial.println("ledRed_pin is turn off");
count = 0;
}
digitalWrite(ledRed_pin, LOW);
}
}
'arduino_' 카테고리의 다른 글
조도센서---> led_Green (0) | 2015.09.08 |
---|---|
Random_led_four (0) | 2015.08.24 |
기초(switch(ON)-> LED(ON), switch(OFF)-> LED(OFF)) (0) | 2015.08.24 |
arduino_Ultra_seven_segment_count (0) | 2015.08.24 |
arduino_Ultra_distance_led_three (0) | 2015.08.24 |
기초(switch(ON)-> LED(ON), switch(OFF)-> LED(OFF))
const int switchPin = 2;
const int ledRed = 13;
int result;
void setup() {
// put your setup code here, to run once:
pinMode(ledRed, OUTPUT);
pinMode(switchPin, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
result = digitalRead(switchPin);
if(result == HIGH)
{
digitalWrite(ledRed, HIGH);
}
else
{
digitalWrite(ledRed, LOW);
}
}
'arduino_' 카테고리의 다른 글
조도센서---> led_Green (0) | 2015.09.08 |
---|---|
Random_led_four (0) | 2015.08.24 |
기초1(switch(1)-> led(on), switch(2)-> led(off) (0) | 2015.08.24 |
arduino_Ultra_seven_segment_count (0) | 2015.08.24 |
arduino_Ultra_distance_led_three (0) | 2015.08.24 |
arduino_Ultra_seven_segment_count
byte digits[10][7] =
{
{1,1,1,1,1,1,0},//0
{0,1,1,0,0,0,0},//1
{1,1,0,1,1,0,1},//2
{1,1,1,1,0,0,1},//3
{0,1,1,0,0,1,1},//4
{1,0,1,1,0,1,1},//5
{1,0,1,1,1,1,1},//6
{1,1,1,0,0,0,0},//7
{1,1,1,1,1,1,1},//8
{1,1,1,1,0,1,1}//9
};
const int trig = 10;
const int echo = 11;
int l= 0;
int End = 2;
int Start = 1;
void setup() {
// put your setup code here, to run once:
for(int i =2; i<10; i++)
{
pinMode(i, OUTPUT);
}
digitalWrite(9,HIGH);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
Serial.begin(9600);
displayDigit(0);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
long distance = pulseIn(echo, HIGH)/58.2;
Serial.println(distance);
if(l!=0)
{
if(distance<50)
{
for(int i=Start; i<End; i++)
{
delay(1000);
displayDigit(i);
}
Start++;
End++;
}
}
l=1;
}
void displayDigit(int num)
{
int pin = 2;
for(int i=0; i<7; i++)
{
digitalWrite(pin+i, digits[num][i]);
}
}
'arduino_' 카테고리의 다른 글
조도센서---> led_Green (0) | 2015.09.08 |
---|---|
Random_led_four (0) | 2015.08.24 |
기초1(switch(1)-> led(on), switch(2)-> led(off) (0) | 2015.08.24 |
기초(switch(ON)-> LED(ON), switch(OFF)-> LED(OFF)) (0) | 2015.08.24 |
arduino_Ultra_distance_led_three (0) | 2015.08.24 |
arduino_Ultra_distance_led_three
const int ledRed = 13;
const int ledBlue = 12;
const int ledGreen = 11;
const int trig = 3;
const int echo = 2;
void setup() {
// put your setup code here, to run once:
pinMode(ledRed, OUTPUT);
pinMode(ledBlue , OUTPUT);
pinMode(ledGreen, OUTPUT);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
long distance = pulseIn(echo, HIGH)/58.2;
delay(10);
Serial.print(distance);
Serial.println(" cm");
if(distance > 4 && distance <15)
{
digitalWrite(ledBlue, LOW);
digitalWrite(ledGreen, LOW);
digitalWrite(ledRed, HIGH);
delay(500);
}
else if(distance >= 15 && distance <30)
{
digitalWrite(ledRed, LOW);
digitalWrite(ledGreen, LOW);
digitalWrite(ledBlue, HIGH);
delay(500);
}
else
{
digitalWrite(ledRed, LOW);
digitalWrite(ledBlue, LOW);
digitalWrite(ledGreen, HIGH);
delay(500);
}
}
'arduino_' 카테고리의 다른 글
조도센서---> led_Green (0) | 2015.09.08 |
---|---|
Random_led_four (0) | 2015.08.24 |
기초1(switch(1)-> led(on), switch(2)-> led(off) (0) | 2015.08.24 |
기초(switch(ON)-> LED(ON), switch(OFF)-> LED(OFF)) (0) | 2015.08.24 |
arduino_Ultra_seven_segment_count (0) | 2015.08.24 |