33
Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อใหนักศึกษาเขาใจการใชงาน 7-Segment Display 2. เพื่อใหนักศึกษาเขาใจและสราง เครื่องหยอดเหรียญโรตีสายไหม 2. เนื้อหา 2.1 Arduino Shield Arduino ทุกเวอรชั่น (ยกเวนพวกที่เปน SMD และ เวอรชั่นที่ทําขึ้นกันเอง) จะถูกออกแบบใหมี Layout ของ Pin ตางๆในรูปแบบเดียวกัน เพื่อใหสามารถใชอุปกรณเสริมหลายๆอยางรวมกันได โดย วิธี Plug n' play หมายถึงแคเสียบลงไปแลวก็นําไปใชงานไดเลย .... ทําใหอุปกรณเสริมที่นํามาใชตอพวง รวมกันเรียกวา Shield (ซึ่งหมายถึง เกราะ หรืออะไรประมาณนั้น ประมาณวา สวมเกราะเสร็จ ออกไป รบไดเลย) เมื่อมีการนําอุปกรณมาตอพวงก็ตองพูดถึงการ เขียนโปรแกรม ... ซึ่งแนนอนบน Arduino (หรือ บอรดที่เปน Arduino Compatible อยาง Intel Galileo) เราจะพึ่งการใชงานจาก Library เปนสวน ใหญ Shield สวนใหญจะพวงมาพรอมกับ Library สําหรับใชงานกับ Shield ของตนเอง เรียกวา นอกจากจะแค Plug in เขามา แลวยัง Play งายๆดวย Library ที่ใหมาดวยเลย (งานนี้ไมตองพึ่ง Cheat code กันเลยทีเดียว) Shield สวนใหญจะใช ICSP Connector ในการเชื่อมตอกับ Arduino board (หรือ Galileo board) โดยเมื่อเชื่อมตอ Shield แลวเรายังสามารถใชงาน Digital pin และ Analog pin บางอันไดอยู (หมายถึงวา เราจะเสียการเชื่อมตอบางอันไปให Shield ทํางาน) ในปจจุบันมีการออกแบบให Shield ใช ทรัพยากรในการเชื่อมตอกับบอรดนอยที่สุด ทําใหสามารถเชื่อมตอกับอุปกรณอื่นๆไดมากขึ้น สําหรับ Arduino นั้น Shield เปนอุปกรณเสริมที่สําคัญ เพราะทําใหเราสามารถ "เลนกับมัน" ได มากขึ้น โดยเฉพาะ Shield ที่เปนประโยชนตอผูเขียนมากก็คือ Ethernet Shield เพราะในยุคของ IoT (Internet of Things) อะไรก็เปนการเชื่อมตอผานระบบเครือขาย เก็บขอมูลไวบน Cloud เสียหมด แต บน Intel Galileo นั้น Ethernet Shield จะไมมีความหมายอีกตอไป เพราะถูกทดแทนดวย Ethernet ที่ถูกฝงมาพรอมกับบอรดอยูแลว... รูปที่ 1 เปนตัวอยางของ Arduino Shield ที่มีจําหนายจากราน Online ขอควรระวัง ในการใช งาน คือ เมื่อใช Shield มากกวาหนึ่งบอรดตองระวังเรื่องการซอนทับกันของขาใชงาน เมื่อเลือกบอรด แลวตองเพิ่ม Library เขากับ Arduino IDE กอนใชงาน

Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

  • Upload
    others

  • View
    12

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Arduino Class-11: Tick Tock Shield: 7-Segment Display

1. วัตถุประสงค1. เพื่อใหนักศึกษาเขาใจการใชงาน 7-Segment Display2. เพื่อใหนักศึกษาเขาใจและสราง เครื่องหยอดเหรียญโรตีสายไหม

2. เนื้อหา2.1 Arduino Shield

Arduino ทุกเวอรชั่น (ยกเวนพวกที่เปน SMD และ เวอรชั่นที่ทําข้ึนกันเอง) จะถูกออกแบบใหมีLayout ของ Pin ตางๆในรูปแบบเดียวกัน เพื่อใหสามารถใชอุปกรณเสริมหลายๆอยางรวมกันได โดยวิธี Plug n' play หมายถึงแคเสียบลงไปแลวก็นําไปใชงานไดเลย.... ทําใหอุปกรณเสริมที่นํามาใชตอพวงรวมกันเรียกวา Shield (ซึ่งหมายถึง เกราะ หรืออะไรประมาณนั้น ประมาณวา สวมเกราะเสร็จ ออกไปรบไดเลย)

เมื่อมีการนําอุปกรณมาตอพวงก็ตองพูดถึงการ เขียนโปรแกรม ... ซึ่งแนนอนบน Arduino (หรือบอรดที่เปน Arduino Compatible อยาง Intel Galileo) เราจะพึ่งการใชงานจาก Library เปนสวนใหญ Shield สวนใหญจะพวงมาพรอมกับ Library สําหรับใชงานกับ Shield ของตนเอง เรียกวานอกจากจะแค Plug in เขามา แลวยัง Play งายๆดวย Library ที่ใหมาดวยเลย (งานนี้ไมตองพึ่ง Cheatcode กันเลยทีเดียว)

Shield สวนใหญจะใช ICSP Connector ในการเชื่อมตอกับ Arduino board (หรือ Galileoboard) โดยเมื่อเชื่อมตอ Shield แลวเรายังสามารถใชงาน Digital pin และ Analog pin บางอันไดอยู(หมายถึงวา เราจะเสียการเชื่อมตอบางอันไปให Shield ทํางาน) ในปจจุบันมีการออกแบบให Shield ใชทรัพยากรในการเชื่อมตอกับบอรดนอยที่สุด ทําใหสามารถเชื่อมตอกับอุปกรณอ่ืนๆไดมากข้ึน

สําหรับ Arduino นั้น Shield เปนอุปกรณเสริมที่สําคัญ เพราะทําใหเราสามารถ "เลนกับมัน" ไดมากข้ึน โดยเฉพาะ Shield ที่เปนประโยชนตอผูเขียนมากก็คือ Ethernet Shield เพราะในยุคของ IoT(Internet of Things) อะไรก็เปนการเชื่อมตอผานระบบเครือขาย เก็บขอมูลไวบน Cloud เสียหมด แตบน Intel Galileo นั้น Ethernet Shield จะไมมีความหมายอีกตอไป เพราะถูกทดแทนดวย Ethernetที่ถูกฝงมาพรอมกับบอรดอยูแลว...

รูปที่ 1 เปนตัวอยางของ Arduino Shield ที่มีจําหนายจากราน Online ขอควรระวัง ในการใชงาน คือ เมื่อใช Shield มากกวาหนึ่งบอรดตองระวังเรื่องการซอนทับกันของขาใชงาน เมื่อเลือกบอรดแลวตองเพิ่ม Library เขากับ Arduino IDE กอนใชงาน

Page 2: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 2 of 33

รูปที่ 1 ตัวอยาง Arduino Shield

Page 3: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 3 of 33

2.2 การเพิ่ม Library ใหกับ Arduino IDEไลบรารี่ (Libraries) คือ คือชุดของโคดโปรแกรมที่มีคนอ่ืนเขียนไวแลว เชน สาํหรับการใชงาน

เซ็นเซอรตางๆ, การใชงานหนาจอ LCD, Wife Shield, GPS โมดูล และสวนขยายตางๆ โดยที่เราไมตองมาเขียนข้ึนใหม เราแคทําการเพิ่มไลบรารี่ใน Arduino IDE ก็สามารถนาํมาใชงานไดทันททีําใหเราไมตองมาวุนวาย ปวดหัวกับการเขียนโปรแกรม วาจะเขียนเพื่อใหใชงาน สวนขยายตางๆของ Arduino อยางไรเอาเวลามาใชกับความคิดสรางสรรค วาจะประดิษฐอะไร ดกีวา

ซึ่งจํานวนไลบรารี ่นั้นก็มีอยูมากมายเปนรอยๆไลบรารี่ใหเราไดเลือกใชหากเราทําการติดตั้งArduino IDE จะมีไลบรารี่ที่มากับตัวติดตั้งเลยเรียกวาไลบรารี่มาตราฐาน

รายการไลบรารี่มาตราฐาน Standard Libraries EEPROM สําหรับอานและเขียน สําหรับ หนวยความจํา EEPROM Ethernet สาํหรับการเชื่อมตออินเตอรเน็ต โดยใช Arduino Ethernet Shield Firmata สําหรับการสือสารกับโปรแกรมบนคอมพิวเตอรโดยใช serial protocol GSM สําหรับการเชื่อมตอกับเครือขาย GSM/GRPS ดวย GSM Shield LiquidCrystal สําหรับการควบคุมการแสดงผลจอ LCD SD สําหรับการอานและเขียน SD การด Servo สําหรับควบคุม มอเตอรเซอรโว SPI สาํหรับการสือสารกับอุปกรณอ่ืนๆโดยใช Serial Peripheral Interface (SPI) Stepper สําหรับการควบคุม สเต็ปเปอร มอเตอร TFT สําหรับการแสดงผลตัวอักษร , รูปภาพ และ รูปทรงตางๆ บน จอภาพ TFT WiFi สําหรับการเชื่อมตอกับอินเตอรเน็ต โดยใช Wifi Shield

Page 4: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 4 of 33

วิธีการเพิ่มไลบรารี่ มาตราฐานใน โคดโปรแกรม1. พิมพเอาเอง โดยสามารถพิมพชื่อ ไลบรารี่โดยใชคําสั่ง

#include <ชื่อไลบรารี่>2. ใชการเลือกจากเมนู Sketch Include Library ชื่อไลบรารี่ ซึ่งจะทําการเพิ่มไลบรารี่ให

โดยอัตโนมัติ

Page 5: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 5 of 33

วิธีการติดตั้งไลบรารี่ใหมวิธีที่ 1 ใช Library Manager

1. ไปที่เมนู Sketch → Include Library → Manage Libraries...

2. จะมีหนาตางแสดงรายการไลบรารี่ ที่ติดตั้งแลวและยังไมไดทําการติดตั้ง ซึ่งเราสามารถเลื่อนหารายการ ไลบรารี่ที่เราตองการได

Page 6: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 6 of 33

3. ไลบรารี่ตัวไหนที่ติดตั้งเรียบรอยแลวจะแสดงคําวา INSTALLED

4. ตัวอยางการติดตั้งไลบรารี:่ จอ Nokia 5110 และตองการไลบรารี่เพื่อใชควบคุมจอภาพ

5. เราสามารถพิมพ คนหาในชองคนหา เพื่อหาไลบรารี่ที่เราตองการ ในที่นี้ใหพิมพ nokia จะแสดงรายการที่เราตองการข้ึนมา และใหกดเลือกรายการนั้น จะมีปุม Install เพื่อใหเราทําการติดตั้งไลบรารี่

Page 7: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 7 of 33

6. Arduino IDE จะทําการโหลดตัวไลบรารี่จากอินเตอรเน็ต แะเมื่อติดตั้งเรียบรอยแลวจะเปลี่ยนเปน INSTALLED แสดงวาการติดตั้งไลบรารี่ใหมเรียบรอย

7. ที่เมนู Sketch จะมีไลบรารี่ Nokia 5110 LCD Library ในรายการ พรอมใหเราใชแลวครับ

Page 8: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 8 of 33

วิธีที่ 2 ติดตั้งไลบรารี่แบบ .ZIP ไลบรารี่1. ไลบรารี่บางตัวที่เราตองการนํามาใช อาจจะอยูในรูปแบบของ .ZIP ไฟล ที่สามารถดาวนโหลดได

จากอินเตอรเน็ต เมื่อเราดาวนโหลดมาแลว เราตองทําการ อิมพอรตไลบรารี่มาไวในตัว IDE กอนทําไดโดยไปที่เมนู Sketch ของตัว IDE Sketch → Include Library → Add .Zip Library...

2. แลวทําการเลือกไฟล .zip ของไลบรารี่ที่เราโหลดมาจากอินเตอรเน็ต

วิธีที่ 3 ติดตั้งดวยตัวเอง1. วิธีการนี้เมื่อเราทําการดาวนโหลดไฟล ไลบรารี่มาแลว ซึ่งอาจะอยูในรูปแแบบของ .ZIP ไฟล

หรือรูปแบบของไฟลบีบอัดชนิดอ่ืนๆ เชน .TAR, .RAR ใหเราทําการ ขยายไฟลใหเรียบรอย2. แลวนําไปวางที่ C:\Program Files(x86)\Arduino\libraries\ เปนอันใชได3. ตัวอยางการเพิ่มไลบรารี่เอง : Tick Tock Shield

Page 9: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 9 of 33

ดาวนโหลด Library ไฟล จาก http://www.seeedstudio.com/wiki/Tick_Tock_Shield_Kit

Unzip “Tick_Tock_Shield_libraries.Zip” จะได 4 โฟลเดอร

คัดลอกทั้ง 4 โฟลเดอร นําไปวางที่ C:\Program Files(x86)\Arduino\libraries\ ปดหนาตาง Arduino IDE ทุกหนาตาง แลวเปดใหมจะปรากฏ Tick Tock Library ข้ึนมา

Page 10: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 10 of 33

2.3 Tick Tock Shield1 Introduction

Real time clock shield เปนชีลสาํหรับการเริ่มตนเรียนรู การเขียนโปรแกรมควบคุมอุปกรณตางๆที่หลากหลายและแตกตางกันออกไปเปนชีลที่รวมหลายๆอุปกรณไวในชีลเดียว ผูใชจะไดเรียนรูการเขียนโปรแกรมควบคุมสวนตางๆ เชนหลอดไฟ LED, เสียง Buzzer, เวลา Real TimeClock, การแสดงผล 7-Segment, InputButtons, Light Sensor, Temperature Sensorเปนตน เหมาะสําหรับผูเริ่มตนการเขียนโปรแกรมหรือเริ่มตนเรียนรูดาน Microcontroller

(*ใชงานกับ Arduino UNO R3 เทานั้น*ไมสามารถใชกับ Arduino Mega 2560 R3 หรือบอรดอ่ืนได เนื่องจากขา I2C ไมตรงกัน ยกเวนจะทําการตอสายแยกดานนอก)

2 Specifications

Page 11: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 11 of 33

Hardware Resources Coin Cell Holder: provides power to RTC IC when external power is off; Buzzer: create audio effect; Light Sensor: detect ambient light intensity; Temperature Sensor: detect ambient temperature; K1...K3: temporary buttons; D1...D4: LEDs; U3: DS1307, Real Time Clock IC; U5: TM1636, 7-seg display driver IC.

Pins Used On Arduino D2: control LED1; D3: control LED2; D4: control LED3; D5: control LED4; D6: control buzzer; D7: TM1636 SCLK pin; D8: TM1636 DIO pin;

D9: control K1; D10: control K2; D11: control K3; A0(D14): poll readings from temperature sensor; A1(D15): poll readings from light sensor; A4(D18): DS1307 SDA pin A5(D19): DS1307 SCK pin

3 DemonstrationsWe start to present you 7 demos from easy to difficult. They involve usage of all

hardware resources on Tick Tock Shield: Demo 1: Sweep The LEDs Demo 2: Control LEDs By Keys Demo 3: Change The Pitch Of Buzzer By Keys Demo 4: Display Temperature Demo 5: Make A Light Sensor Controlled LED Demo 6: Display Numerical Characters Demo 7: Real Time Clock

Page 12: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 12 of 33

3.1 Preparation: Install the Hardware and Software1. Plug Tick Tock Shield onto Arduino board. Connect Arduino to PC via USB

cable as show below.

2. Download the file:Tick Tock Shield Library fromhttp://www.seeedstudio.com/wiki/File:Tick_Tock_Shield_libraries.zip

3. Unzip and put 4 folder in the libraries file of Arduino IDE by the path:..\arduino-1.0.1\libraries.

Note:1) Libraries MsTimer2 and Timerone are packed in Tick Tock Shield Library we

prvide above. We download them from Arduino website. If you already havethem in your libraries file, them no need to add them once again.

2) Through all 7 demos in Tick Tock Shield library, we define: K3 - menu key K2 - increase key K1 - decrease key D4 - LED_CLOCK_ADJUST D3 - LED_ALARM_ADJUST D2 - LED_ALARM_ENABLE D1 - LED_BRIGHT_ADJUST

Page 13: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 13 of 33

3.2 Getting Started: Fun with Tick Tock ShieldFrom easy to difficult, we prepared a series of demos for you to explore what your Tick

Tock Shield is capable of. Follow me to have fun with it.

Demo 1: Sweep The LEDs1. This demo only involves the usage of the most basic actuator - LEDs.2. Restart the Arduino IDE. Open the example "RunLED" via the path: File -->

Examples --> TickTockShield--> RunLED.3. This demo can sweep 4 LEDs with a settable speed. You can change the

sweep speed by changing the parameter of the function "runLED(speed)". Findfurther illutration of the funtion in its comment.

4. Click the upload button to upload the program to the Arduino.5. You can see four LED lights turn on and off from left to right at a given speed after

the program is uploaded.

Demo 2: Control LEDs By KeysThis demo shows you how to control LEDs with the most basic input - buttons.

1. Open the example "ControlLED" in the same way as open the “RunLED” above.2. This demo can turn on or off four LEDs by keys. We set two flags to store the

status of this test, TEST_START and TEST_END. Every time the “menu” key getspressed, the status toggles between TEST_START and TEST_END. In the status ofTEST_START, "increase" key can turn on one more LED from right to left everytime it gets pressed. The "decrease" key has an inverse effect as the "increase"key.

Demo 3: Change The Pitch Of Buzzer By KeysThis demo involves how to make a sound with buzzer, and because you have already knownhow to use buttons, in this demo, we use buttons to increase or decrease the pitch of buzzer.

1. Open the example "changeThePitch".2. Every time the “increase” key gets pressed, the pitch of the buzzer will rise up.

And when the “decrease” key gets pressed, the pitch will fall down.

Page 14: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 14 of 33

Demo 4: Display TemperatureGet started with sensors. First we have here is the temperature sensor. Try to read its valueand display it on the 7 segment display.

1. Open the example“MeasureTemprature”.

2. The 7-segment Display will displaycurrent temperature read fromtemperature sensor as shown below.

3. If you find in the picture below, thecontrast is not strong enough, try alower view angle. These principlesalso apply to following demos whichcontain usage of 7-segment display.

Demo 5: Make A Light Sensor Controlled LEDIs it convenient if the brightness of display can auto adjust itself according to the ambientlight? This demo shows you how to do this by using a light sensor.

1. Open the example“SensorControlBrightness” in thesame way.

2. This example can change thebrightness of BRIGHT_ADJUSTIndicator according to the ambientlight intensity. The darker theenvironment is, the lighter the LEDturns. Picture on the right is theturnout.

Demo 6: Display Numerical CharactersThis demo shows you how to control the content of 7 segment display.

1. Open the example “CharacterFlow”.2. 2. This example can run numeric

characters 0, 1, 2, 3, 4, 5, 6, 7, 8 ,9,A, b, C, d, E, F from right to left

Page 15: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 15 of 33

Demo 7: Real Time ClockThis is a final demo that involves all

hardware resources we mentioned aboveand performs all functions of a real lifealarm clock, like time display, making abuzz to get you out of your bed and so on.What's more, because a light sensor and atemperature sensor are added, Tick TockShield does more than a normal alarmclock. It can sense the ambient light andauto-adjust the brightness of 7-segmentdisplay. Also it can show you the currenttemperature at a given time interval.

1. Open the example "RealTimeClock" and upload the example into Arduino.2. The 7-segment Display will alternately display current time and temperature.3. Method to adjust the time and set the alarm clock:

1) Because there is a RTC chip on board, so you don't need to reset the timeevery time you turn it on, of course, the condition is the coin battery for RTCchip is alive. But if this is your first time to start up the Tick Tock Shield, timesetting is required.

2) Three buttons are used to adjust the time. They are "menu"(K3), "increase"(K2)and "decrease"(K1). Press "memu" to cycle between the next setting modes:

a) set the hour part of normal time displayb) set the minute part of normal time displayc) set the hour part of alarm clockd) set the minute part of alarm clocke) set the default brightness of 7 segment displayf) turn on or off the alarm functiong) quit time setting modes

3) If you want to quit before processing all 7 steps above. There are twointerruption ways. One, press K3 no matter on which step for 3s. In this way,Tick Tock Shield will confirm all settings you have made and quit. Two, leavethe Tick Tock Shield alone for 5s. In this way. No setting will be stored andyou quit time setting mode also.

4) K2 is assigned to set the status of alarm clock. You can know the status ofalarm clock via ALARM_ENABLE Indicator.

4 Resources Tick Shield Library Tick Shield eagle file Tick_Shield_Schematic

Tm1636 datasheet DS1307N datasheet

Page 16: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 16 of 33

5 References5.1 EEPROM Class

Class Function: Read and write EEPROM of AVR chip. The EEPROM size ofATmega328P Chip is 1K Bytes for Seeeduino V3.0. The contents of the EEPROM you have wrotewill not be lost when power off. It is used for saving alarm time and alarm enable flag in theRealTimeClock Demo, You don't need to reset the alarm clock.

Function Description:1. EEPROM.read(int address)This function is used to read data from a specified address of EEPROM.

address: the address of the targeted unit.Example:

temp_data[i] = EEPROM.read(i);

2. EEPROM.write(int address, uint8_t value);The function is used to write data to a specified address of EEPROM.

address: the address of the targeted unit uint8_t value: data to be written to the targetted unit.

Example:

if(temp_data[i] != mark[i]) { EEPROM.write(0,mark[0]); EEPROM.write(1,mark[1]); EEPROM.write(2,mark[2]); EEPROM.write(3,mark[3]); EEPROM.write(4,mark[4]); return true; }

Page 17: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 17 of 33

5.2 TM1636 classClass Function:this class contains all funtions to control four 7-segment displays.

Function Description:1. tm1636.point(boolean PointFlag);The function is used to turn on or off the clock point (:). This function will come into effectevery time the display content changes.

PointFlag: can be 0(off) or 1(on).Example:

if(flag_clockpoint) { tm1636.point(POINT_ON); } else tm1636.point(POINT_OFF);

2. Tm1636.display(int8_t DispData[]);Create a character flow with the content of DispData[].

DispData[]: an array in int8_t type, including 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, A, b, C, d, Eand F.

Example:

tm1636.display(disp);

5.3 TickTockShield ClassClass Function:Operate all components on the Tick Tock Shield.

Function Description1. ticktockshield.init();The Initialization of Tick Tock Shield.

2. ticktockshield.runLED(byte speed, byte direction);This function sweeps 4 LEDs in the direction you choose.

speed: the the LED flow rate from 1(slowest) to 10(fastest). direction: LED flow direction, can be LEFT_TO_RIGHT or RIGHT_TO_LEFT.

Example:

/*Run the 4 LEDs from left to right*/ticktockshield.runLED(1,LEFT_TO_RIGHT);

Page 18: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 18 of 33

3. ticktockshield. turnOnLED();Turn on all 4 LEDs.

4. ticktockshield. turnOffLED();Turn off all 4 LEDs.

5. setLed(unsigned char led_status, int pinLED);The Function is used to turn on or off an individual LED.

led_status: can be LED_ON or LED_OFF. pinLED: can be one of LED_CLOCK_ADJUST,LED_ALARM_ADJUST,

LED_BRIGHT_ADJUST,LED_ALARM_ENABLE.Example:

void TickTockShield::turnOffLED(){

setLed(LOW,LED_CLOCK_ADJUST);setLed(LOW,LED_ALARM_ADJUST);setLed(LOW,LED_BRIGHT_ADJUST);setLed(LOW,LED_ALARM_ENABLE);

}

6. ticktockshield.alarming();Let the buzzer buzz.Example:

/*It will sound alarm for a minute untill the "MENU" key is pressed*/ if(ticktockshield.isAlarmEnable()) { ticktockshield.alarming(); }

7. ticktockshield.turnOffAlarm();Turn off the alarm when the buzzer is buzzing.

8. ticktockshield.setAlarm(uint8_t hour,uint8_t minute,uint8_t flag_enabl);Set the alarm time.

hour: hour minute: minute flag_enabl: flag that restores the status of alarm, can be 0(unenabled) or 1(enabled)

Example:

ticktockshield.setAlarm(12,0);//Yes,the alarm clock is initialized to 12:00 and the data in theEEPROM.

Page 19: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 19 of 33

9. ticktockshield.getAlarm();Read the preset alarm value from EEPROM and store them into given variables, including theenable flag of the alarm.Example:

if(isFirstLoad())//if it is the first time to load the firmware?{

ticktockshield.setAlarm(12,0);}else ticktockshield.getAlarm();//No,read the alarm clock stored in EEPROM

10. ticktockshield.getTemperature();Get the reading from temperature sensor.Example:

/*Read the ambient temperature and display on the digital tube.*/ticktockshield.displayTemperature(ticktockshield.getTemperature());

11. ticktockshield.displayTemperature(int8_t temperature);Display temperature value(negative value supported) on the 7 segment display. The characterC represents celsius degrees.Example:

ticktockshield.displayTemperature(ticktockshield.getTemperature());

12. ticktockshield.scanKey();Find out which key gets pressed. Return the pin number of the key pressed. And return "-1" ifno keys is pressed.

if((flag_scan_again)&&(KEY_MENU == ticktockshield.scanKey())) {

ticktockshield.writeToAdjustArea(); ticktockshield.processKey(); system_states = SYSTEM_ADJUSTING; }

13. ticktockshield.processKey();Process the command you enter through keys. If it's a normal press. This function will make abuzz corresponding to the press. If you press the "menu" key longer than 3s, then thisfunction will make Tick Tock Shield enter time setting mode. If no other key gets pressed afterthe "menu" key, then this function will make Tick Tock Shield quit the time setting mode.

Page 20: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 20 of 33

14. ticktockshield.processSystemStatus();Execute different tasks according to the system status when it's called. The system status canbe "adjust clock time"、 "alarm time", "adjust 7 segment display brightness" and "enablealarm".

15. ticktockshield.writeToAdjustArea();Deliver the latest time information from normal time display mode to time setting mode so thatthey can be used under time setting mode.

16. ticktockshield.writeToNormalArea();Deliver the time information set in time setting mode to normal time display mode.

17. ticktockshield.writeTime();Write time information into RTC chip.

18. ticktockshield.getTime();Read the current time information from RTC.

19. ticktockshield.displayTime();Display time on 7 segment Display.Example:

if(ticktockshield.isAlarmEnable()) { tm1636.point(POINT_ON); ticktockshield.displayTime(); system_states = SYSTEM_ALARMING; return; }

20. ticktockshield.display(int8_t DispData []);Display alpha-numeric information 7 segment Display.

Page 21: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 21 of 33

2.4 Segment DisplayLED คือ Diode ประเภทหนึ่ง

7_Segment: คือ LED จํานวน 7 ตัวนํามาตอรวมกัน แบงการตอออกเปน 2 ชนิด คือCommon Cathode และ Common Anode

Display BIN (tgfe dcba) HEX Display BIN (tgfe dcba) HEX0 81 92 A3 B4 C5 D6 E7 F

Page 22: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 22 of 33

2.5 Experiment Code

Test1/7 Digital IO

//_Test0101_DigitalIO

//-------pin definition of LEDs---------------//#define LED_CLOCK_ADJUST 5#define LED_ALARM_ADJUST 4#define LED_ALARM_ENABLE 3#define LED_BRIGHTNESS_ADJUST 2//-------pin definition of keys---------------//#define KEY_MENU 11#define KEY_UP 10#define KEY_DOWN 9

const int LEDS_PIN[] ={ LED_BRIGHTNESS_ADJUST,

LED_ALARM_ENABLE,LED_ALARM_ADJUST,LED_CLOCK_ADJUST

};

char LED_on_number = -1;

void setup(){ init_pins();}

void loop(){ if(digitalRead(KEY_MENU)==LOW)

{ while(digitalRead(KEY_MENU)==LOW){ turnOnAll();

delay(300);turnOffAll();delay(300);

}}

if(digitalRead(KEY_UP)==LOW){ turnOnMoreLED();

delay(300);while(digitalRead(KEY_UP)==LOW);

}

if(digitalRead(KEY_DOWN)==LOW){ turnOffMoreLED();

delay(300);while(digitalRead(KEY_DOWN)==LOW);

}}

//=====================================================/*Initialization for the hardware,and should be called first*/void init_pins()

{ /*set keys to be inputs and define the initial status as HIGH*/pinMode(KEY_MENU, INPUT); digitalWrite(KEY_MENU, HIGH);pinMode(KEY_UP, INPUT); digitalWrite(KEY_UP, HIGH);pinMode(KEY_DOWN, INPUT); digitalWrite(KEY_DOWN, HIGH);

/*define the pin mode of LEDs*/pinMode(LED_CLOCK_ADJUST, OUTPUT);pinMode(LED_ALARM_ADJUST, OUTPUT);pinMode(LED_BRIGHTNESS_ADJUST, OUTPUT);pinMode(LED_ALARM_ENABLE, OUTPUT);turnOffAll(); //Turn off all the LEDs first.

}

Page 23: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 23 of 33

/*Turn on one LED*/inline void turnOn(int pinLED)

{ digitalWrite(pinLED, HIGH);}

/*Turn Off one LED*/inline void turnOff(int pinLED)

{ digitalWrite(pinLED, LOW);}

/*Turn on all the LEDs*/inline void turnOnAll()

{ turnOn(LED_CLOCK_ADJUST);turnOn(LED_ALARM_ADJUST);turnOn(LED_BRIGHTNESS_ADJUST);turnOn(LED_ALARM_ENABLE);

}

/*Turn off all the LEDs*/inline void turnOffAll()

{ turnOff(LED_CLOCK_ADJUST);turnOff(LED_ALARM_ADJUST);turnOff(LED_BRIGHTNESS_ADJUST);turnOff(LED_ALARM_ENABLE);

}

/*Turn on one more LED*/void turnOnMoreLED()

{ if(LED_on_number < 3) //when not all LEDs are on{ LED_on_number ++;

turnOn(LEDS_PIN[LED_on_number]);for(byte i = LED_on_number + 1;i < 4;i ++)

turnOff(LEDS_PIN[i]); //make sure the higher ranked LEDs are off}

}

/*Turn off one more LED*/void turnOffMoreLED()

{ if((LED_on_number > 0) || (LED_on_number == 0)) //when not all LEDs are off{ turnOff(LEDS_PIN[LED_on_number]);

LED_on_number --;}

}

Page 24: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 24 of 33

Test2/7 Segment Display

//_Test0201_SegDisplay

#include "TM1636.h"//--Declare a TM1636 Class object that control the 4-digit display--//TM1636 tm1636(7,8);

void setup(){ /*Set the default brightness is BRIGHT_TYPICAL and clear the display*/ tm1636.init();}

void loop(){ int8_t disp[4]; //store the index of the 4 digit to display. int8_t Counter;

Counter = 0; disp[0] = Counter++; disp[1] = Counter++; disp[2] = Counter++; disp[3] = Counter++; tm1636.display(disp); //display on the 4-digit display. delay(300); while(1);}

//_Test0202_SegDisplay

#include "TM1636.h"//--Declare a TM1636 Class object that control the 4-digit display--//TM1636 tm1636(7,8);

void setup(){ /*Set the default brightness is BRIGHT_TYPICAL and clear the display*/ tm1636.init();}

void loop(){ int8_t disp[4]; //store the index of the 4 digit to display. int8_t Counter; for(Counter = 0; Counter<=15; Counter++) { if((Counter-3)<0) disp[0] = INDEX_BLANK; else disp[0] = Counter-3; if((Counter-2)<0) disp[1] = INDEX_BLANK; else disp[1] = Counter-2; if((Counter-1)<0) disp[2] = INDEX_BLANK; else disp[2] = Counter-1; if((Counter-0)<0) disp[3] = INDEX_BLANK; else disp[3] = Counter-0; tm1636.display(disp); //display on the 4-digit display. delay(500); }}

Page 25: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 25 of 33

Test3/7 LDR

//_Test0301_LDR

#include "TM1636.h"#define LIGHT_SENSOR A1#define LED_D4 5#define LED_D3 4#define LED_D2 3#define LED_D1 2

TM1636 tm1636(7,8);

void setup(){ pinMode(LED_D4,OUTPUT); pinMode(LED_D3,OUTPUT); pinMode(LED_D2,OUTPUT); pinMode(LED_D1,OUTPUT); Serial.begin(9600); tm1636.init();}

void loop(){ int sensorValue = analogRead(LIGHT_SENSOR); Serial.print(sensorValue); Serial.print("-"); if(sensorValue>500) digitalWrite(LED_D4,HIGH); else digitalWrite(LED_D4,LOW); if(sensorValue>400) digitalWrite(LED_D3,HIGH); else digitalWrite(LED_D3,LOW); if(sensorValue>300) digitalWrite(LED_D2,HIGH); else digitalWrite(LED_D2,LOW); if(sensorValue>200) digitalWrite(LED_D1,HIGH); else digitalWrite(LED_D1,LOW); DisplayInt(sensorValue); delay(300);}

void DisplayInt(int DataIn){ int8_t temp,disp[4]; DataIn = DataIn % 10000; temp = DataIn / 1000; DataIn = DataIn % 1000; disp[0] = temp; temp = DataIn / 100; DataIn = DataIn % 100; disp[1] = temp; temp = DataIn / 10; DataIn = DataIn % 10; disp[2] = temp; temp = DataIn / 1; DataIn = DataIn % 1; disp[3] = temp; tm1636.display(disp); //display on the 4-digit display.*/ Serial.println();}

Page 26: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 26 of 33

Test4/7 Temperature////_Test0401_Temperature//

#include "TM1636.h"//-Declare the resistance of the resistor that connects with the temperature sensor-//#define RESISTOR_CONNECT_THERMISTOR 10000//the resistance is 8k ohm//-------pin definition of temperature sensor-------------//#define TEMPERATURE_SENSOR A0

TM1636 tm1636(7,8);

void setup(){ pinMode(TEMPERATURE_SENSOR, INPUT); Serial.begin(115200); tm1636.init();}

void loop(){ float temperature; /*Read the ambient temperature and display on the digital tube.*/ temperature = getTemperature(); displayTemperature(temperature); Serial.println(temperature,4); delay(500);}

/****************************************************************//*Return:int8_t,Temperature that range from -40 to 125 degrees. */float getTemperature(){ float temperature,resistance; int a = analogRead(TEMPERATURE_SENSOR); resistance = (float)(1023-a)*RESISTOR_CONNECT_THERMISTOR/a; //Calculate theresistance of the thermistor int B = 3975; /*Calculate the temperature according to the following formula.*/ temperature = 1/(log(resistance/RESISTOR_CONNECT_THERMISTOR)/B+1/298.15)-273.15; return temperature;// the type convert from floating point to 8-bit integer}

/*********************************************************************//*Function:Display 8-bit integer temperature on the 4-digit display. */void displayTemperature(int8_t temperature){ int8_t temp[4]; if(temperature < 0) //if the temperature is below zero? { temp[0] = INDEX_NEGATIVE_SIGN; // then the left-most bit will display “-“ temperature = abs(temperature); } else if(temperature < 100) //if temperature >= 0 and temperature < 100? temp[0] = INDEX_BLANK; else //if temperature > 100? temp[0] = temperature/100;

temperature %= 100; temp[1] = temperature / 10;//index of second bit from left temp[2] = temperature % 10;//index of the third bit from left temp[3] = 12; //index of 'C' for celsius degree symbol. tm1636.display(temp);}

Page 27: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 27 of 33

Test5/7 DS1307_RTC//// _Test0505_DS1307RTC//#include "Wire.h"#include "TM1636.h"#define DS1307_I2C_ADDRESS 0x68TM1636 tm1636(7,8);char Second,Minute,Hour,lastSecond=99;

void setup(){ Wire.begin(); tm1636.init(); Serial.begin(9600);

//Hour = 12; Minute = 34; Second = 56; SetTime_DS1307(); // want to setup time}

void loop(){ GetTime_DS1307(); if(lastSecond!=Second) { lastSecond = Second;

DisplayTime(); Serial.print((byte)Hour); Serial.print(":"); Serial.print((byte)Minute); Serial.print(":"); Serial.println((byte)Second); }}

//=======================================================inline byte decToBcd(byte val){ return ( (val/10*16) + (val%10) );}

inline byte bcdToDec(byte val){ return ( (val/16*10) + (val%16) );}

void SetTime_DS1307(){ Wire.beginTransmission(DS1307_I2C_ADDRESS); Wire.write(decToBcd(0)); Wire.write(decToBcd(Second)); Wire.write(decToBcd(Minute)); Wire.write(decToBcd(Hour)); Wire.endTransmission();}

void GetTime_DS1307(){ Wire.beginTransmission(DS1307_I2C_ADDRESS); Wire.write(decToBcd(0)); Wire.endTransmission(); Wire.requestFrom(DS1307_I2C_ADDRESS, 3); Second = bcdToDec(Wire.read() & 0x7f); Minute = bcdToDec(Wire.read()); Hour = bcdToDec(Wire.read() & 0x3f);}

void DisplayTime(void){ int8_t disp[4]; //store the index of the 4 digit to display. disp[0] = Hour/10; disp[1] = Hour%10; disp[2] = Minute/10; disp[3] = Minute%10; tm1636.display(disp); if(Second&1==1) tm1636.point(POINT_ON); else tm1636.point(POINT_OFF);}

Page 28: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 28 of 33

Test6/7 Counter_EEPROM//// _Question0101_Counter//#include "TM1636.h"#include "EEPROM.h"TM1636 tm1636(7,8);int PB_Zero = 11;int PB_INC = 10;int Counter = 0;

void setup(){ Counter = EEPROM.read(4) << 8; Counter = Counter | EEPROM.read(5); pinMode(PB_Zero,INPUT_PULLUP); pinMode(PB_INC,INPUT_PULLUP); tm1636.init(); Display_Int(Counter);}

void loop(){ if(digitalRead(PB_Zero)==LOW) { Counter = 0; EEPROM.write(4,(Counter>>8)&0xff); EEPROM.write(5,(Counter>>0)&0xff); Display_Int(Counter); delay(100); while(digitalRead(PB_Zero)==LOW); delay(100); }

if(digitalRead(PB_INC)==LOW) { Counter++; EEPROM.write(4,(Counter>>8)&0xff); EEPROM.write(5,(Counter>>0)&0xff); Display_Int(Counter); delay(100); while(digitalRead(PB_INC)==LOW); delay(100); }}

void Display_Int(int DataIn){ boolean Check = HIGH; int8_t disp[4]; if((DataIn < 1000)&(Check == HIGH)) disp[0] = INDEX_BLANK; else { disp[0] = DataIn /1000; DataIn = DataIn%1000; Check = LOW; } if((DataIn < 100)&(Check == HIGH)) disp[1] = INDEX_BLANK; else { disp[1] = DataIn /100; DataIn = DataIn%100; Check = LOW; } if((DataIn < 10)&(Check == HIGH)) disp[2] = INDEX_BLANK; else { disp[2] = DataIn / 10;DataIn = DataIn%10; Check = LOW; } disp[3] = DataIn; tm1636.display(disp);}

Page 29: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 29 of 33

Test7/7 Pk_RTC//// _MyClock//#include "Wire.h"#include "TM1636.h"#define DS1307_I2C_ADDRESS 0x68#define RESISTOR_CONNECT_THERMISTOR 10000#define TEMPERATURE_SENSOR A0#define PB_Mode 11#define PB_SetHH 10#define PB_SetMM 9

TM1636 tm1636(7,8);char Second,Minute,Hour,lastSecond=99;

void setup(){ Wire.begin(); tm1636.init(); pinMode(TEMPERATURE_SENSOR, INPUT); pinMode(PB_Mode, INPUT_PULLUP); pinMode(PB_SetHH, INPUT_PULLUP); pinMode(PB_SetMM, INPUT_PULLUP); Serial.begin(9600); //Hour = 21; Minute = 50; Second = 56; SetTime_DS1307();}

void loop(){ GetTime_DS1307(); if(Second==10) DisplayTemperature(); if(digitalRead(PB_Mode)==LOW) DisplayTemperature(); if(digitalRead(PB_SetHH)==LOW) AddHour(); if(digitalRead(PB_SetMM)==LOW) AddMinute(); if(lastSecond!=Second) { lastSecond = Second; DisplayTime(); Serial.print((byte)Hour); Serial.print(":"); Serial.print((byte)Minute); Serial.print(":"); Serial.println((byte)Second); }}

//=======================================================inline byte decToBcd(byte val){ return ( (val/10*16) + (val%10) );}

inline byte bcdToDec(byte val){ return ( (val/16*10) + (val%16) );}

void SetTime_DS1307(){ Wire.beginTransmission(DS1307_I2C_ADDRESS); Wire.write(decToBcd(0)); Wire.write(decToBcd(Second)); Wire.write(decToBcd(Minute)); Wire.write(decToBcd(Hour)); Wire.endTransmission();}

Page 30: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 30 of 33

void GetTime_DS1307(){ Wire.beginTransmission(DS1307_I2C_ADDRESS); Wire.write(decToBcd(0)); Wire.endTransmission(); Wire.requestFrom(DS1307_I2C_ADDRESS, 3); Second = bcdToDec(Wire.read() & 0x7f); Minute = bcdToDec(Wire.read()); Hour = bcdToDec(Wire.read() & 0x3f);}

void DisplayTime(void){ int8_t disp[4]; //store the index of the 4 digit to display. disp[0] = Hour/10; disp[1] = Hour%10; disp[2] = Minute/10; disp[3] = Minute%10; if(Second&1==1) tm1636.point(POINT_ON); else tm1636.point(POINT_OFF); tm1636.display(disp);}

//=======================================================void DisplayTemperature(void){ int8_t temp[4]; int temperature; temperature = (int)(getTemperature()*10); temp[0] = temperature / 100; temperature %= 100; temp[1] = temperature / 10; temperature %= 10; temp[2] = temperature % 10; temp[3] = 12; tm1636.point(POINT_ON);

tm1636.display(temp); delay(5000);}

//== Return:int8_t,Temperature that range from -40 to 125 degrees.float getTemperature(void){ float temperature,resistance; //Calculate the resistance of the thermistor int AA = analogRead(TEMPERATURE_SENSOR); resistance = (float)(1023-AA)*RESISTOR_CONNECT_THERMISTOR/AA;

/*Calculate the temperature according to the following formula.*/ int BB = 3975; temperature = 1/(log(resistance/RESISTOR_CONNECT_THERMISTOR)/BB+1/298.15)-273.15;

return temperature; // the type convert from floating point to 8-bit integer}

void AddHour(void){ Hour++; if(Hour>23) Hour=0; SetTime_DS1307(); DisplayTime(); delay(100); while(digitalRead(PB_SetHH)==LOW); delay(100);}

Page 31: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 31 of 33

void AddMinute(void){ Minute++; if(Minute>59) Minute=0; SetTime_DS1307(); DisplayTime(); delay(100); while(digitalRead(PB_SetMM)==LOW); delay(100);}

2.6 Reference www.makertut.com/tutorials/การเพิ่มไลบรารี่ใหกับ-arduino-ide https://sites.google.com/site/e22mhs/embedded/galileo/what-is-shield

Page 32: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 32 of 33

ใบงานวันที่ 28 ธันวาคม 2558PC เลขที่ ________ เลขที่ ________ ชื่อ____________________________PC เลขที่ ________ เลขที่ ________ ชื่อ____________________________

โจทย1. จากโปรแกรม Test1/7 Digital IO ใหอธิบายการทํางานของโปรแกรม

2. จากโปรแกรม Test2/7 Segment Displayเปนโปรแกรมนับเลขข้ึนจาก 0 ถึง F แบบดันเลขไปทางซายทีละตัว ถาตองการใหนับลงแลวดันเลขไปทางขวา จะปรับโปรแกรมอยางไร

3. จากโปรแกรม Test3/7 LDR โปรแกรมจะอานคา LDR มาแสดงที่ 7_Segment Display เมื่อเอาปด LDR โปรแกรมจะสั่งให LED ปดลง ใหอธิบายการทาํงานของโปรแกรม

Check 1/2

Page 33: Arduino Class-11: Tick Tock Shield: 7-Segment Display 1 ... · Arduino Class-11: Tick Tock Shield: 7-Segment Display 1. วัตถุประสงค 1. เพื่อให

Page 33 of 33

4. จากโปรแกรม Test4/7 Temperature เปนโปรแกรมอานอุณหภูมิจาก Termister ถาตองการแสดงอุณหภูมิทศนิยมหนึ่งตําแหนงตองปรับโปรแกรมอยางไร

5. จากโปรแกรม Test5/7 DS1307_RTC ใหอธิบายการทํางานของโปรแกรม (หากตองการตั้งเวลาใหทําการ uncomment บรรทัด // Hour = 12; Minute = 34; Second = 56;

SetTime_DS1307(); // want to setup time )

6. จากโปรแกรม Test6/7 Counter_EEPROM ใหอธิบายการทํางานของโปรแกรม

7. จากโปรแกรม Test7/7 Pk_RTC ใหอธิบายการทํางานของโปรแกรม

Check 2/2