2017년 2월 7일 화요일

7. RGB MOUBLE

1. 실체도





















2. Sample Source Code

/*     ---------------------------------------------------------
 *     |  Experimentation Kit for Arduino Example Code         |
 *     |  CIRC-RGB .: Colourful Light :. (RGB LED)             |
 *     ---------------------------------------------------------
 *
 * We've blinked an LED and controlled eight in sequence now it's time to
 * control colour. Using an RGB LED (actual 3 LEDs in a single housing) 
 * we can generate any colour our heart desires.
 *
 * (we'll also use a few programming shortcuts to make the code
 * more portable/readable)
 */


//RGB LED pins
int ledDigitalOne[] = {10, 11, 9}; //the three digital pins of the digital LED
                                   //10 = redPin, 11 = greenPin, 9 = bluePin

const boolean ON = HIGH;     //Define on as LOW (this is because we use a common
                            //Anode RGB LED (common pin is connected to +5 volts)
const boolean OFF = LOW;   //Define off as HIGH

//Predefined Colors
const boolean RED[] = {ON, OFF, OFF};   
const boolean GREEN[] = {OFF, ON, OFF};
const boolean BLUE[] = {OFF, OFF, ON};
const boolean YELLOW[] = {ON, ON, OFF};
const boolean CYAN[] = {OFF, ON, ON};
const boolean MAGENTA[] = {ON, OFF, ON};
const boolean WHITE[] = {ON, ON, ON};
const boolean BLACK[] = {OFF, OFF, OFF};

//An Array that stores the predefined colors (allows us to later randomly display a color)
const boolean* COLORS[] = {RED, GREEN, BLUE, YELLOW, CYAN, MAGENTA, WHITE, BLACK};

void setup(){
  for(int i = 0; i < 3; i++){
   pinMode(ledDigitalOne[i], OUTPUT);   //Set the three LED pins as outputs
  }
}

void loop(){

/* Example - 1 Set a color
   Set the three LEDs to any predefined color
*/
   setColor(ledDigitalOne, GREEN);    //Set the color of LED one

/* Example - 2 Go through Random Colors
  Set the LEDs to a random color
*/
   randomColor();

}

void randomColor(){
  int rand = random(0, sizeof(COLORS) / 2);  //get a random number within the range of colors
  setColor(ledDigitalOne, COLORS[rand]);  //Set the color of led one to a random color
  delay(1000);
}

/* Sets an led to any color
   led - a three element array defining the three color pins (led[0] = redPin, led[1] = greenPin, led[2] = bluePin)
   color - a three element boolean array (color[0] = red value (LOW = on, HIGH = off), color[1] = green value, color[2] =blue value)
*/
void setColor(int* led, boolean* color){
 for(int i = 0; i < 3; i++){
   digitalWrite(led[i], color[i]);
 }
}

/* A version of setColor that allows for using const boolean colors
*/
void setColor(int* led, const boolean* color){
  boolean tempColor[] = {color[0], color[1], color[2]};
  setColor(led, tempColor);

}

라벨:

6. 1602 Character LCD

1. 1602LCD 실체








2. Sample source code

//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>                            // I2C control library
#include <LiquidCrystal_I2C.h>          // LCD library

LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x20 for a 16 chars and 2 line display

void setup()
{
  lcd.init();                      // initialize the lcd

  // Print a message to the LCD.
  lcd.backlight();  // turn on backlight
  //lcd.print("  Hellow !");
 
 
}

void loop()
{
  lcd.print("  Hellow !");
 
  delay(2000);
  lcd.clear();

  delay(2000);

라벨:

5. SRD-05VDC-SL-C

1. 구성도















2.회로도











3. sample source code

int relay = 10; //릴레이에 5V 신호를 보낼 핀설정
void setup ()
{
  pinMode (relay, OUTPUT); // relay를 output으로 설정한다.
}
void loop ()
{
  digitalWrite (relay, HIGH); // 릴레이 ON
  delay (10000);              //10초 delay
  digitalWrite (relay, LOW); // 릴레이 OFF

  delay (5000);               //5초 delay

라벨:

4. 적외선센서를 이용한 아두이노

2. 그림 설명:적외선센서에 물체를 가까이하면 붉은색 led등이 켜진다.

3. 연결방법

적외선 센서(FC-51)
VCC     -   5V
GND    -   GND
OUT     -   3~

LED                       
+          -    2
-           -   GND


3. 소스 코드
const int irDetectPin = 3; //FC-51 Pin 설정
 const int ledPin = 2; //LED Pin 설정
void setup() {
 pinMode(irDetectPin, INPUT); //FC-51 입력으로 설정
 pinMode(ledPin, OUTPUT); //LED 출력으로 설정 }

 void loop() {
 int noDetect = digitalRead(irDetectPin); //FC-51 상태 읽어오기
 if(noDetect) //FC-51포트가 HIGH이면 즉, 감지 안되었다면
 digitalWrite(ledPin, 0); //LED Off
else //LOW 즉, 감지 되었다면
 digitalWrite(ledPin, 1); //LED ON
 }

FC-51에서 나오는 값이 HIGH 이면 감지가 안되고 있다는 얘기이고
LOW 떨어지면 장애물이 감지되었다는 것이다.



라벨:

2016년 2월 11일 목요일

2. RGB Module test

이 모듈은 led 등을 아두이노를 통하여 여러색의 빛이 나도록 제어할 수 있다

라벨:

2016년 2월 5일 금요일

1.Seven segment test in arduino

아두이노 led seven segment test

 Arduino pin: 2,3,4,5,6,7,8
byte seven_seg_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,0,0,1,1 }   // = 9
                                                           };

void setup() {              
  pinMode(2, OUTPUT); 
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  writeDot(0);  // start with the "dot" off
}

void writeDot(byte dot) {
  digitalWrite(9, dot);
}
  
void sevenSegWrite(byte digit) {
  byte pin = 2;
  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pin, seven_seg_digits[digit][segCount]);
    ++pin;
  }
}

void loop() {
  for (byte count = 10; count > 0; --count) {
   delay(1000);
   sevenSegWrite(count - 1);
  }
  delay(4000);
}

reference ->http://www.hacktronics.com/Tutorials/arduino-and-7-segment-led.html

라벨: