Skip to content

Instantly share code, notes, and snippets.

@prasertsakd
Created July 25, 2015 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prasertsakd/9c363236d4df55315466 to your computer and use it in GitHub Desktop.
Save prasertsakd/9c363236d4df55315466 to your computer and use it in GitHub Desktop.
byte seven_seg_digits[11][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,1,0,1,1 }, // = 9
{ 0,0,0,0,0,0,0 } // = none
};
int ledPins[] = { 6,7,8,9,10,11,12,13};
unsigned char SevenSegmentDigi[] = { A2, 4, 5};
int pinCount = 8; // the number of pins (i.e. the length of the array)
int timer = 500; // The higher the number, the slower the timing.
int count = 9;
long previousMillis = 0; // will store last time LED was updated
#define led 0
#define vr 1
#define ldr 2
#define temp 3
int state=0;
void setup() {
Serial.begin(9600);
//configure pin2 as an input and enable the internal pull-up resistor
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(14, INPUT_PULLUP);
pinMode(15, INPUT_PULLUP);
pinMode(SevenSegmentDigi[0],OUTPUT);
pinMode(SevenSegmentDigi[1],OUTPUT);
pinMode(SevenSegmentDigi[2],OUTPUT);
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(ledPins[thisPin], OUTPUT);
}
// writeDot(0); // start with the "dot" off
}
void writeDot(byte dot) {
digitalWrite(ledPins[7], dot);
}
void sevenSegWrite(byte digit) {
byte pin = 0;
for (byte segCount = 0; segCount < 7; ++segCount) {
digitalWrite(ledPins[pin], seven_seg_digits[digit][segCount]);
++pin;
}
}
void ControlSegmentDigi( byte val)
{
for (int i=0; i<3 ;i++)
if (val != i)
digitalWrite(SevenSegmentDigi[i],HIGH);
digitalWrite(SevenSegmentDigi[val],LOW);
}
int thisPin=0;
int st=1;
void loop() {
if (state == led) {
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(A2,LOW);
timer = map(analogRead(A3), 0, 1023, 10, 500);
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
digitalWrite(ledPins[thisPin], LOW);
thisPin = thisPin + st;
if (thisPin >= 8) {
thisPin=0;//st = -1;
}
//if (thisPin <= 0) st = 1;
} else {
byte digi2 = count /100;
byte digi1 = (count % 100) / 10.0;
byte digi0 = (count % 10);
//byte digi2 = (count - (digi1*100))/10.0;
//byte digi3 = count - (digi1*100)-(digi2*10);
//if (digi1==0) digi1=10;
//writeDot(false);
sevenSegWrite(digi0);
ControlSegmentDigi(2);
delay(3);
//writeDot(true);
sevenSegWrite(digi1);
ControlSegmentDigi(1);
delay(3);
//writeDot(false);
sevenSegWrite(digi2);
ControlSegmentDigi(0);
delay(3);
}
if (digitalRead(2) == LOW)
state = led;
if (digitalRead(3) == LOW)
state = vr;
if (digitalRead(14) == LOW)
state = ldr;
if (digitalRead(15) == LOW)
state = temp;
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > 42) {
previousMillis = currentMillis;
if (state == vr)
count = map(analogRead(A3), 0, 1023, 0, 999);
if (state == ldr)
count = map(analogRead(A4), 0, 1023, 0, 999);
if (state == temp) {
count = ( 5.0 * analogRead(A4) * 100.0) / 102.40;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment