Last active
December 19, 2016 15:10
-
-
Save maxpromer/97137847bec53d132589127a00bd1305 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CounterSensorDisplay by IOXhop.com | |
#include <TM1637Display.h> | |
// Module connection pins (Digital Pins) | |
#define CLK 3 // กำหนดว่าขา CLK ต่ออยู่กับขา D3 | |
#define DIO 2 // กำหนดว่าขา DIO ต่ออยุ่กับขา D2 | |
#define D0Sensor 4 // กำหนดว่าขา D0 ของ Counter / Speed Sensor ต่ออยู่กับขา D4 | |
TM1637Display display(CLK, DIO); // เริ่มใช้งานไลบารี่ | |
int i; // ประกาศตัวแปร i เป็นชนิด int เก็บข้อมูลตัวเลขจำนวนเต็ม | |
void setup() | |
{ | |
pinMode(D0Sensor, INPUT); // กำหนดให้ขาที่ต่อกับ D0 ของเซ็นเซอร์เป็นขาอินพุต | |
} | |
void loop() | |
{ | |
if (digitalRead(D0Sensor)==HIGH) { // ถ้าขาที่ต่อกับ D0 มีสถานะเป็น HIGH | |
while(digitalRead(D0Sensor)==HIGH); // ให้รอจนกว่าขาที่ต่อกับ D0 เป็น LOW | |
i++; // เพิ่มค่าในตัวแปร i ขึ้น 1 จำนวน | |
} | |
display.print(i); // แสดงผลค่า i ออกทางหน้าจอ 7 Segment | |
delay(10); // หน่วงเวลา 10mS | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment