Skip to content

Commit e9bcae6

Browse files
committed
Added Predator segment control example.
1 parent 43e42f7 commit e9bcae6

File tree

2 files changed

+98
-8
lines changed

2 files changed

+98
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
11-21-2012
3+
Spark Fun Electronics
4+
Nathan Seidle
5+
6+
This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
7+
8+
Serial7Segment is an open source seven segment display.
9+
10+
This is example code that shows how to control individual segments on each digit. Sort of like
11+
the Predator display at the end of the movie when he blows himself up.
12+
13+
Note: This code expects the display to be listening at 9600bps. If your display is not at 9600bps, you can
14+
do a software or hardware reset. See the Wiki for more info:
15+
http://github.com/sparkfun/Serial7SegmentDisplay/wiki/Special-Commands#wiki-baud
16+
17+
To get this code to work, attached an Serial7Segment to an Arduino Uno using the following pins:
18+
Pin 7 on Uno (software serial RX) to TX on Serial7Segment
19+
Pin 8 on Uno to RX on Serial7Segment
20+
VIN to PWR
21+
GND to GND
22+
23+
*/
24+
25+
//From https://github.com/sparkfun/Serial7SegmentDisplay/wiki/Special-Commands#wiki-individual
26+
#define SEGMENT1 0
27+
#define SEGMENT2 1
28+
#define SEGMENT3 2
29+
#define SEGMENT4 3
30+
#define SEGMENT5 4
31+
#define SEGMENT6 5
32+
#define SEGMENT7 6
33+
34+
#define DIGIT1 0x7B
35+
#define DIGIT2 0x7C
36+
#define DIGIT3 0x7D
37+
#define DIGIT4 0x7E
38+
39+
#include <SoftwareSerial.h>
40+
41+
SoftwareSerial Serial7Segment(7, 8); //RX pin, TX pin
42+
43+
int cycles = 0;
44+
45+
void setup() {
46+
47+
Serial.begin(9600);
48+
Serial.println("OpenSegment Example Code");
49+
50+
Serial7Segment.begin(9600); //Talk to the Serial7Segment at 9600 bps
51+
Serial7Segment.write('v'); //Reset the display - this forces the cursor to return to the beginning of the display
52+
53+
//Here's the basic example
54+
Serial7Segment.write(DIGIT1); // Control individual segments on a digit
55+
Serial7Segment.write( (1<<SEGMENT1) | (1<<SEGMENT4) | (1<<SEGMENT7) ); // Turn on certain segments
56+
57+
Serial7Segment.write(DIGIT2); // Control individual segments on a digit
58+
Serial7Segment.write( (1<<SEGMENT2) | (1<<SEGMENT5) | (1<<SEGMENT7) ); // Turn on certain segments
59+
60+
Serial7Segment.write(DIGIT3); // Control individual segments on a digit
61+
Serial7Segment.write( (1<<SEGMENT4) | (1<<SEGMENT5) ); // Turn on certain segments
62+
63+
Serial7Segment.write(DIGIT4); // Control individual segments on a digit
64+
Serial7Segment.write( (1<<SEGMENT5) | (1<<SEGMENT6) | (1<<SEGMENT7) ); // Turn on certain segments
65+
66+
delay(1500);
67+
68+
//Here's the more fun example
69+
70+
//Seed random generator with analog input - nothing needs to be connected to A0
71+
randomSeed(analogRead(0));
72+
}
73+
74+
void loop()
75+
{
76+
for(int x = 0 ; x < 4 ; x++)
77+
{
78+
byte randNumber = random(0, 127); //Give me random number between 0 and 127
79+
Serial7Segment.write(DIGIT1 + x); //Control individual segments on a digit
80+
Serial7Segment.write(randNumber); //Turn on random segments
81+
}
82+
83+
delay(1000);
84+
}
85+
86+
87+

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ 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 S7S
38+
#define DISPLAY_TYPE OPENSEGMENT
3939

4040
//Global variables for the analog pins
4141
unsigned int analogValue6 = 0;
@@ -118,16 +118,16 @@ void setup()
118118
// The display is constantly PWM'd in the loop()
119119
void loop()
120120
{
121-
analogValue6 = analogRead(A6);
122-
analogValue7 = analogRead(A7);
121+
/*analogValue6 = analogRead(A6);
122+
analogValue7 = analogRead(A7);*/
123123

124124
//Serial.print("A6: ");
125125
//Serial.print(analogValue6);
126126
//Serial.print(" A7: ");
127127
//Serial.print(analogValue7);
128128

129129
//Do calculation for 1st voltage meter
130-
float fvoltage6 = ((analogValue6 * 50) / (float)1024);
130+
/*float fvoltage6 = ((analogValue6 * 50) / (float)1024);
131131
int voltage6 = round(fvoltage6);
132132
display.digits[0] = voltage6 / 10;
133133
display.digits[1] = voltage6 % 10;
@@ -139,13 +139,12 @@ void loop()
139139
display.digits[3] = voltage7 % 10;
140140
141141
display.decimals = ((1<<DECIMAL1) | (1<<DECIMAL3)); //Turn on the decimals next to digit1 and digit3
142-
143142
myDisplay.DisplayString(display.digits, display.decimals); //(numberToDisplay, decimal point location)
144-
143+
*/
145144

146145

147146
// long myTimer = millis();
148-
// myDisplay.DisplayString(display.digits, display.decimals); //(numberToDisplay, decimal point location)
147+
myDisplay.DisplayString(display.digits, display.decimals); //(numberToDisplay, decimal point location)
149148
// Serial.print("Timer: ");
150149
// Serial.println(millis() - myTimer);
151150
}
@@ -313,7 +312,11 @@ void setupDisplay()
313312
int displayType = COMMON_CATHODE; //SparkFun 1" displays are common cathode
314313

315314
//Initialize the SevSeg library with all the pins needed for this type of display
316-
myDisplay.Begin(displayType, numberOfDigits, digit1, digit2, digit3, digit4, segA, segB, segC, segD, segE, segF, segG, segDP);
315+
myDisplay.Begin(displayType, numberOfDigits,
316+
digit1, digit2, digit3, digit4,
317+
segA, segB, segC, segD, segE, segF, segG,
318+
segDP);
319+
317320
#endif
318321
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
319322

0 commit comments

Comments
 (0)