Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const byte digit_pins[3] = {5,6,7};
- const byte data_pin = 2;
- const byte sh_pin = 4;
- const byte st_pin = 3;
- unsigned long tm, next_flick, generator_flick;
- const unsigned int to_flick = 1;
- const unsigned int to_generator_low = 1;
- const unsigned int to_generator_high = 2;
- int sensorValue = 0;
- float voltage = 0;
- byte digit = 0;
- byte is_high = 0;
- unsigned int counter = 0;
- const byte digits[10] = {
- B11101110,
- B10000010,
- B11011100,
- B11010110,
- B10110010,
- B01110110,
- B01111110,
- B11000010,
- B11111110,
- B11110110
- };
- void fill( byte d ){
- for(char i=0; i<8; i++){
- digitalWrite(sh_pin, LOW);
- digitalWrite(data_pin, digits[d] & (1«i));
- digitalWrite(sh_pin, HIGH);
- }
- digitalWrite(st_pin, HIGH);
- digitalWrite(st_pin, LOW);
- }
- void setDigit( byte digit, unsigned int counter ){
- byte d = 0;
- switch ( digit ){
- case 0:
- digitalWrite(digit_pins[2], LOW);
- d = counter % 10;
- fill(d);
- digitalWrite(digit_pins[0], HIGH);
- break;
- case 1:
- digitalWrite(digit_pins[0], LOW);
- d = (counter % 100) / 10;
- fill(d);
- digitalWrite(digit_pins[1], HIGH);
- break;
- case 2:
- digitalWrite(digit_pins[1], LOW);
- d = ( counter % 1000 ) / 100;
- fill(d);
- digitalWrite(digit_pins[2], HIGH);
- break;
- }
- }
- void setup() {
- for(int i=0; i<3; i++){
- pinMode(digit_pins[i], OUTPUT);
- }
- pinMode(data_pin, OUTPUT);
- pinMode(sh_pin, OUTPUT);
- pinMode(st_pin, OUTPUT);
- pinMode(13, OUTPUT);
- pinMode(8,OUTPUT);
- digitalWrite(8,HIGH);
- pinMode(9,OUTPUT);
- }
- void set_generator(byte high)
- {
- if (high == 0)
- digitalWrite(9, LOW);
- if (high == 1)
- digitalWrite(9, HIGH);
- }
- void loop() {
- tm = millis();
- if( tm > next_flick ){
- next_flick = tm + to_flick;
- digit++;
- if( digit == 3 )
- digit = 0;
- sensorValue = analogRead(A0);
- voltage = sensorValue * (10010 / 1023.0)/10;
- setDigit( digit, voltage );
- }
- tm = millis();
- if (tm > generator_flick) {
- ++is_high;
- if (is_high == 2)
- is_high = 0;
- if (is_high == 0)
- generator_flick = tm + to_generator_low;
- else
- generator_flick = tm + to_generator_high;
- set_generator(is_high);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement