Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void setup()
- {
- DDRD |= 0b111100;
- PORTD ^= 0b111100;
- delay(10);
- PORTD ^= 0b111100;
- Serial.begin(115200);
- }
- unsigned long last = 0;
- byte digits[4] = {
- 2, 4, 7, 1};
- byte positions[4] = {
- 1, 4, 6, 9};
- void loop()
- {
- while(!(PIND & 0b10000000));
- unsigned long micro = micros();
- unsigned long duration = micro - last;
- last = micro;
- unsigned long pdigit = duration / 10 - duration / 150;
- unsigned int blinkduration = pdigit / 50;
- for(byte c = 0; c < 4; c++)
- {
- while(micros() < micro + positions[c] * pdigit + pdigit / 4);
- PORTD ^= _BV(c + 2);
- delayMicroseconds(blinkduration);
- PORTD ^= _BV(c + 2);
- }
- if(Serial.available() >= 4)
- {
- Serial.readBytes((char*)positions, 4);
- for(byte b = 0; b < 4; b++)
- positions[b] = 10 - (positions[b] - '0') + b;
- }
- while(PIND & 0b10000000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement