Code
#include "LedControl.h"
LedControl lc=LedControl(5,7,6,1);
// Pin 5->DIN, 7->CLK, 6->CS(LOAD), 1 = No.of devices
void show4digit(int num)
{
int seg1,seg2,seg3,seg4;
seg1 = ((num%1000)%100)%10;
seg2 = ((num%1000)%100)/10;
seg3 = (num%1000)/100;
seg4 = num/1000;
lc.setDigit(0,0,seg1,false);
if (num>=10)
lc.setDigit(0,1,seg2,false);
if (num>=100)
lc.setDigit(0,2,seg3,false);
if (num>=1000)
lc.setDigit(0,3,seg4,false);
delay(300);
}
void setup()
{
Serial.begin(9600);
lc.shutdown(0,false);
lc.setIntensity(0,5);
lc.clearDisplay(0);
}
void loop()
{
int num;
num = analogRead(A0);
Serial.print("analogRead=");Serial.println(num);
lc.clearDisplay(0);
show4digit(num);
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น