Skip to content

Commit 43e42f7

Browse files
committed
Experimenting with volt meter display.
Works well. Not sure where to put the A/D checking. Not in the main loop. Perhaps a dedicated function where we only go if a jumper is closed.
1 parent 9f94cb6 commit 43e42f7

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

firmware/Serial 7-Segment Display/Serial_7_Segment_Display_Firmware/Serial_7_Segment_Display_Firmware.ino

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ SevSeg myDisplay; //Create an instance of the object
3535
//OpenSegment uses PNP and NPN transistors to drive larger displays
3636
#define S7S 1
3737
#define OPENSEGMENT 2
38-
#define DISPLAY_TYPE OPENSEGMENT
38+
#define DISPLAY_TYPE S7S
39+
40+
//Global variables for the analog pins
41+
unsigned int analogValue6 = 0;
42+
unsigned int analogValue7 = 0;
3943

4044
// Struct for circular data buffer data received over UART, SPI and I2C are all sent into a single buffer
4145
struct dataBuffer
@@ -98,6 +102,7 @@ void setup()
98102
setupUART(); // initialize UART stuff (interrupts, enable, baud)
99103
setupSPI(); // Initialize SPI stuff (enable, mode, interrupts)
100104
setupTWI(); // Initialize I2C stuff (address, interrupt, enable)
105+
setupAnalog(); // Initialize the analog inputs
101106

102107
interrupts(); // Turn interrupts on, and les' go
103108

@@ -113,8 +118,34 @@ void setup()
113118
// The display is constantly PWM'd in the loop()
114119
void loop()
115120
{
116-
// long myTimer = millis();
121+
analogValue6 = analogRead(A6);
122+
analogValue7 = analogRead(A7);
123+
124+
//Serial.print("A6: ");
125+
//Serial.print(analogValue6);
126+
//Serial.print(" A7: ");
127+
//Serial.print(analogValue7);
128+
129+
//Do calculation for 1st voltage meter
130+
float fvoltage6 = ((analogValue6 * 50) / (float)1024);
131+
int voltage6 = round(fvoltage6);
132+
display.digits[0] = voltage6 / 10;
133+
display.digits[1] = voltage6 % 10;
134+
135+
//Do calculation for 2nd voltage meter
136+
float fvoltage7 = ((analogValue7 * 50) / (float)1024);
137+
int voltage7 = round(fvoltage7);
138+
display.digits[2] = voltage7 / 10;
139+
display.digits[3] = voltage7 % 10;
140+
141+
display.decimals = ((1<<DECIMAL1) | (1<<DECIMAL3)); //Turn on the decimals next to digit1 and digit3
142+
117143
myDisplay.DisplayString(display.digits, display.decimals); //(numberToDisplay, decimal point location)
144+
145+
146+
147+
// long myTimer = millis();
148+
// myDisplay.DisplayString(display.digits, display.decimals); //(numberToDisplay, decimal point location)
118149
// Serial.print("Timer: ");
119150
// Serial.println(millis() - myTimer);
120151
}
@@ -382,6 +413,14 @@ void setupUART()
382413
}
383414

384415
}
416+
417+
//This sets up the two analog inputs
418+
void setupAnalog()
419+
{
420+
pinMode(A6, INPUT);
421+
pinMode(A7, INPUT);
422+
}
423+
385424
// setupSPI(): Initialize SPI, sets up hardware pins and enables spi and receive interrupt
386425
// SPI is set to MODE 0 (CPOL=0, CPHA=0), slave mode, LSB first
387426
void setupSPI()
@@ -451,6 +490,8 @@ void checkEmergencyReset(void)
451490
constantDisplay("0-00", 500);
452491
constantDisplay("-000", 500);
453492
}
493+
494+
//Once we breakout of this loop (pin on RX is removed), system will init with new default settings
454495
}
455496

456497
//Given a string, displays it costantly for a given amount of time

firmware/Serial 7-Segment Display/Serial_7_Segment_Display_Firmware/settings.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@
1818
#define BAUD_500000 10
1919
#define BAUD_1000000 11
2020

21+
//Bit locations for the decimal, apostrophe and colon control
22+
//From https://github.com/sparkfun/Serial7SegmentDisplay/wiki/Special-Commands#wiki-decimal
23+
#define APOSTROPHE 5
24+
#define COLON 4
25+
#define DECIMAL4 3
26+
#define DECIMAL3 2
27+
#define DECIMAL2 1
28+
#define DECIMAL1 0
29+
2130
const int TWI_ADDRESS_DEFAULT = 0x71;
2231
const int BAUD_DEFAULT = BAUD_9600; // 9600 for 8MHz, 2x speed
2332
const int BRIGHTNESS_DEFAULT = 100; // 100%, full brightness

0 commit comments

Comments
 (0)