@@ -35,7 +35,11 @@ SevSeg myDisplay; //Create an instance of the object
35
35
// OpenSegment uses PNP and NPN transistors to drive larger displays
36
36
#define S7S 1
37
37
#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 ;
39
43
40
44
// Struct for circular data buffer data received over UART, SPI and I2C are all sent into a single buffer
41
45
struct dataBuffer
@@ -98,6 +102,7 @@ void setup()
98
102
setupUART (); // initialize UART stuff (interrupts, enable, baud)
99
103
setupSPI (); // Initialize SPI stuff (enable, mode, interrupts)
100
104
setupTWI (); // Initialize I2C stuff (address, interrupt, enable)
105
+ setupAnalog (); // Initialize the analog inputs
101
106
102
107
interrupts (); // Turn interrupts on, and les' go
103
108
@@ -113,8 +118,34 @@ void setup()
113
118
// The display is constantly PWM'd in the loop()
114
119
void loop ()
115
120
{
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
+
117
143
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)
118
149
// Serial.print("Timer: ");
119
150
// Serial.println(millis() - myTimer);
120
151
}
@@ -382,6 +413,14 @@ void setupUART()
382
413
}
383
414
384
415
}
416
+
417
+ // This sets up the two analog inputs
418
+ void setupAnalog ()
419
+ {
420
+ pinMode (A6, INPUT);
421
+ pinMode (A7, INPUT);
422
+ }
423
+
385
424
// setupSPI(): Initialize SPI, sets up hardware pins and enables spi and receive interrupt
386
425
// SPI is set to MODE 0 (CPOL=0, CPHA=0), slave mode, LSB first
387
426
void setupSPI ()
@@ -451,6 +490,8 @@ void checkEmergencyReset(void)
451
490
constantDisplay (" 0-00" , 500 );
452
491
constantDisplay (" -000" , 500 );
453
492
}
493
+
494
+ // Once we breakout of this loop (pin on RX is removed), system will init with new default settings
454
495
}
455
496
456
497
// Given a string, displays it costantly for a given amount of time
0 commit comments