더 재밌게 놀기 연구소
※ Four 7 digital segment with 74 HC595
Circuit
Source Code
int latch=9; //74HC595 pin 12 STCP
int clock=10; //74HC595 pin 11 SHCP
int data=8; //74HC595 pin 14 DS
unsigned char table[]=
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c
,0x39,0x5e,0x79,0x71,0x00};
void setup() {
pinMode(latch,OUTPUT);
pinMode(clock,OUTPUT);
pinMode(data,OUTPUT);
}
void Display(unsigned char num)
{
digitalWrite(latch,LOW);
shiftOut(data,clock,MSBFIRST,table[num]);
digitalWrite(latch,HIGH);
}
void loop() {
Display(1);
delay(500);
Display(2);
delay(500);
Display(3);
delay(500);
Display(4);
delay(500);
Display(5);
delay(500);
Display(6);
delay(500);
Display(7);
delay(500);
Display(8);
delay(500);
Display(9);
delay(500);
Display(10);
delay(500);
Display(11);
delay(500);
Display(12);
delay(500);
Display(13);
delay(500);
Display(14);
delay(500);
Display(15);
delay(500);
}
※ Servo Motor
Circuit
Source Code
//www.elegoo.com
//2016.06.13
/************************************************/
#include <Servo.h>
/************************************************/
Servo myservo;//create servo object to control a servo
/************************************************/
void setup()
{
myservo.attach(9);//attachs the servo on pin 9 to servo object
myservo.write(0);//back to 0 degrees
delay(1000);//wait for a second
}
/*************************************************/
void loop()
{
myservo.write(15);//goes to 15 degrees
delay(1000);//wait for a second
myservo.write(30);//goes to 30 degrees
delay(1000);//wait for a second.33
myservo.write(45);//goes to 45 degrees
delay(1000);//wait for a second.33
myservo.write(60);//goes to 60 degrees
delay(1000);//wait for a second.33
myservo.write(75);//goes to 75 degrees
delay(1000);//wait for a second.33
myservo.write(90);//goes to 90 degrees
delay(1000);//wait for a second
myservo.write(75);//back to 75 degrees
delay(1000);//wait for a second.33
myservo.write(60);//back to 60 degrees
delay(1000);//wait for a second.33
myservo.write(45);//back to 45 degrees
delay(1000);//wait for a second.33
myservo.write(30);//back to 30 degrees
delay(1000);//wait for a second.33
myservo.write(15);//back to 15 degrees
delay(1000);//wait for a second
myservo.write(0);//back to 0 degrees
delay(1000);//wait for a second
}
/**************************************************/
※ LCD
Circuit
Source Code
//www.elegoo.com
//2016.06.13
/*
LiquidCrystal Library - Hello World
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
library works with all LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.
This sketch prints "Hello World!" to the LCD
and shows the time.
The circuit:
* LCD RS pin to digital pin 7
* LCD Enable pin to digital pin 8
* LCD D4 pin to digital pin 9
* LCD D5 pin to digital pin 10
* LCD D6 pin to digital pin 11
* LCD D7 pin to digital pin 12
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
Library originally added 18 Apr 2008
by David A. Mellis
library modified 5 Jul 2009
by Limor Fried (http://www.ladyada.net)
example added 9 Jul 2009
by Tom Igoe
modified 22 Nov 2010
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/LiquidCrystal
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis() / 1000);
}
※ LCD with Thermometer
Circuit
Source Code
//www.elegoo.com
//2016.06.13
/*
Adafruit Arduino - Lesson 12. Light and Temperature
*/
#include <LiquidCrystal.h>
int tempPin = 0;
int lightPin = 1;
// BS E D4 D5 D6 D7
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup()
{
lcd.begin(16, 2);
}
void loop()
{
// Display Temperature in C
int tempReading = analogRead(tempPin);
float tempVolts = tempReading * 5.0 / 1024.0;
float tempC = (tempVolts - 0.5) * 100.0;
float tempF = tempC * 9.0 / 5.0 + 32.0;
// ----------------
lcd.print("Temp F ");
lcd.setCursor(6, 0);
lcd.print(tempF);
// Display Light on second row
int lightReading = analogRead(lightPin);
lcd.setCursor(0, 1);
// ----------------
lcd.print("Light ");
lcd.setCursor(6, 1);
lcd.print(lightReading);
delay(500);
}
'IoT > Arduino' 카테고리의 다른 글
Updated Source Code - Automated Mung Bean Sprouts Growing Machine (0) | 2017.01.27 |
---|---|
Arduino Project 1 - Automated Mung Bean Sprouts Growing Machine (0) | 2017.01.23 |
[Arduino] Motion Sensor and Water Level Sensor (0) | 2017.01.17 |
[Arduino] Joystick, LED Dot Matrix and ADXL335 Module (0) | 2017.01.17 |
[Arduino] Ultrasonic, Keypad and Temperature and Humidity Sensor (0) | 2017.01.15 |
[Arduino] Using 74HC595 8-bit serial-in/serial or parallel-out shift register (0) | 2017.01.12 |
[Arduino] Library and RGB LED (0) | 2017.01.11 |
[Arduino] Servo Motor (0) | 2017.01.10 |
[Arduino] LCD and 7 Segment (0) | 2017.01.10 |
[Arduino] Illuminance (Photocell) and Ultrasonic Sensor (0) | 2017.01.09 |