-
Notifications
You must be signed in to change notification settings - Fork 3
/
sevenseg.h
46 lines (39 loc) · 1.16 KB
/
sevenseg.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* Copyright Ben XO https://github.com/ben-xo All rights reserved.
*/
#ifndef _SEVENSEG_H
#define _SEVENSEG_H
#include <Arduino.h>
#include "config.h"
// these are offsets into PORTB. Because of the way the masking algorithm works with half-bytes,
// you should write into EITHER the lower or upper half. Don't wire your seven seg into a mixture.
#define SEG_G (1<<0)
#define SEG_F (1<<1)
#define SEG_A (1<<2)
#define SEG_B (1<<3)
static uint8_t seven_seg(uint8_t mode)
{
#ifdef SEVEN_SEG_MODE_DISPLAY
switch(mode) {
default: return 0;
case 0: return (SEG_A);
case 1: return (SEG_B);
case 2: return (SEG_G);
case 3: return (SEG_F);
case 4: return (SEG_A | SEG_B);
case 5: return (SEG_B | SEG_G);
case 6: return (SEG_G | SEG_F);
case 7: return (SEG_F | SEG_A);
case 8: return (SEG_A | SEG_B | SEG_G);
case 9: return (SEG_B | SEG_G | SEG_F);
case 10: return (SEG_G | SEG_F | SEG_A);
case 11: return (SEG_F | SEG_A | SEG_B);
case 12: return (SEG_A | SEG_B | SEG_G | SEG_F);
case 13: return (SEG_A | SEG_G);
case 14: return (SEG_F | SEG_B);
}
#else
return mode;
#endif
}
#endif /* _SEVENSEG_H */