Skip to content

Commit 22004e3

Browse files
author
ShawnHymel
committed
Added filled circle and demo sketch.
1 parent 20d06c4 commit 22004e3

File tree

6 files changed

+222
-32
lines changed

6 files changed

+222
-32
lines changed

Libraries/SparkFun_LED_8x7/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Arduino library for the 8x7 LED Charlieplex Array
66
Version
77
-------
88

9-
**v0.1**
9+
**v0.9**
1010

1111
Known Issues
1212
------------
@@ -42,6 +42,11 @@ Getting Started
4242
Version History
4343
---------------
4444

45+
**v0.9**
46+
47+
* Implemented scrolling text, bitmaps, and shapes
48+
* Skipped a bunch of versions because I'm lazy
49+
4550
**v0.1**
4651

4752
* Initial commit

Libraries/SparkFun_LED_8x7/SparkFun_LED_8x7.cpp

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,50 @@ void SparkFun_LED_8x7::circle(uint8_t x0, uint8_t y0, uint8_t radius)
332332
* @param[in] y Y coordinate for the center of the circle
333333
* @param[in] radius Distance (in pixels) from center to edge of circle
334334
*/
335-
void circleFill(uint8_t x0, uint8_t y0, uint8_t radius)
335+
void SparkFun_LED_8x7::circleFill(uint8_t x0, uint8_t y0, uint8_t radius)
336336
{
337-
337+
int8_t y;
338+
int8_t x;
339+
int8_t f;
340+
int8_t ddF_x;
341+
int8_t ddF_y;
342+
int8_t i;
343+
344+
f = 1 - radius;
345+
ddF_x = 1;
346+
ddF_y = -2 * radius;
347+
x = 0;
348+
y = radius;
349+
350+
for ( i = y0 - radius; i <= y0 + radius; i++ ) {
351+
pixel(x0, i);
352+
Serial.print("Drawing (");
353+
Serial.print(x0);
354+
Serial.print(",");
355+
Serial.print(i);
356+
Serial.println(")");
357+
}
358+
359+
while ( x < y ) {
360+
if ( f >= 0 ) {
361+
y--;
362+
ddF_y += 2;
363+
f += ddF_y;
364+
}
365+
x++;
366+
ddF_x += 2;
367+
f += ddF_x;
368+
369+
for ( i = y0 - y; i <= y0 + y; i++ ) {
370+
pixel(x0 + x, i);
371+
pixel(x0 - x, i);
372+
}
373+
374+
for ( i = y0 - x; i <= y0 + x; i++ ) {
375+
pixel(x0 + y, i);
376+
pixel(x0 - y, i);
377+
}
378+
}
338379
}
339380

340381
/**
@@ -488,6 +529,26 @@ void SparkFun_LED_8x7::stopScrolling()
488529
display();
489530
}
490531

532+
/**
533+
* @brief Returns the width of the LED array
534+
*
535+
* @return width of the array (number of LEDs)
536+
*/
537+
uint8_t SparkFun_LED_8x7::getArrayWidth()
538+
{
539+
return ROW_SIZE;
540+
}
541+
542+
/**
543+
* @brief Returns the width of the LED array
544+
*
545+
* @return width of the array (number of LEDs)
546+
*/
547+
uint8_t SparkFun_LED_8x7::getArrayHeight()
548+
{
549+
return COL_SIZE;
550+
}
551+
491552
void SparkFun_LED_8x7::isr()
492553
{
493554

Libraries/SparkFun_LED_8x7/SparkFun_LED_8x7.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ class SparkFun_LED_8x7 {
7676
void scrollText(char *in_string);
7777
void scrollText(char *in_string, int times);
7878
void stopScrolling();
79-
79+
80+
/* Support methods */
81+
uint8_t getArrayWidth();
82+
uint8_t getArrayHeight();
8083

8184
private:
8285

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/****************************************************************
2+
Demo.ino
3+
LED Array 8x7 Charlieplex
4+
Shawn Hymel @ SparkFun Electronics
5+
February 10, 2015
6+
https://github.com/sparkfun/LED_Array_8x7_Charlieplex
7+
8+
Gives a demo of all the functions of the LED array. Once
9+
uploaded, click Tools -> Serial Monitor to see debugging
10+
information.
11+
12+
Hardware Connections:
13+
14+
IMPORTANT: The Charlieplex LED board is designed for 2.0 - 3.3V!
15+
Higher voltages can damage the LEDs.
16+
17+
Arduino Pin | Charlieplex Board
18+
------------|------------------
19+
2 | 2
20+
3 | 3
21+
4 | 4
22+
5 | 5
23+
6 | 6
24+
7 | 7
25+
8 | 8
26+
9 | 9
27+
28+
Resources:
29+
Include Chaplex.h, SparkFun_LED_8x7.h
30+
The Chaplex library can be found at:
31+
http://playground.arduino.cc/Code/Chaplex
32+
33+
Development environment specifics:
34+
Written in Arduino 1.0.6
35+
Tested with SparkFun BadgerStick (Interactive Badge)
36+
37+
This code is beerware; if you see me (or any other SparkFun
38+
employee) at the local, and you've found our code helpful, please
39+
buy us a round!
40+
41+
Distributed as-is; no warranty is given.
42+
****************************************************************/
43+
44+
#include <SparkFun_LED_8x7.h>
45+
#include <Chaplex.h>
46+
47+
// Global variables
48+
byte led_pins[] = {2, 3, 4, 5, 6, 7, 8, 9}; // Pins for LEDs
49+
byte i;
50+
byte x;
51+
byte y;
52+
byte radius;
53+
byte sparkfun_logo[] = { 0,0,0,0,1,0,0,0,
54+
0,0,0,0,1,0,1,0,
55+
0,0,1,0,1,1,1,0,
56+
0,0,1,1,1,1,1,0,
57+
0,0,1,1,1,1,0,0,
58+
0,0,1,1,0,0,0,0,
59+
0,0,1,0,0,0,0,0 };
60+
61+
// Setup code - this runs once
62+
void setup() {
63+
64+
// Initialize the serial port
65+
Serial.begin(9600);
66+
Serial.println("-----------------------");
67+
Serial.println("SparkFun LED 8x7 - Demo");
68+
Serial.println("-----------------------");
69+
70+
// Initialize and clear display
71+
Plex.init(led_pins);
72+
Plex.clear();
73+
Plex.display();
74+
75+
// Seed our random number generator with an analog voltage read
76+
randomSeed(analogRead(0));
77+
}
78+
79+
// Loop code - this runs for infinity
80+
void loop() {
81+
82+
// Show a bitmap
83+
Serial.println("Draw a bitmap");
84+
Plex.clear();
85+
Plex.drawBitmap(sparkfun_logo);
86+
Plex.display();
87+
delay(2000);
88+
89+
// Scroll some text
90+
Serial.println("Scroll some text");
91+
Plex.scrollText("Badges?", 1);
92+
delay(6000);
93+
94+
// Explosions!
95+
Serial.println("Display an animation");
96+
for ( i = 0; i < 15; i++ ) {
97+
x = random(0, 8);
98+
y = random(0, 7);
99+
for ( radius = 0; radius < 12; radius++ ) {
100+
Plex.clear();
101+
Plex.circle(x, y, radius);
102+
Plex.circle(x, y, radius + 1);
103+
Plex.display();
104+
delay(30);
105+
}
106+
}
107+
}

Libraries/SparkFun_LED_8x7/examples/DrawShapes/DrawShapes.ino

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ Distributed as-is; no warranty is given.
4343
#include <Chaplex.h>
4444

4545
// Global variables
46-
byte led_pins[] = {9, 8, 7, 6, 5, 4, 3, 2}; // Pins for LEDs
46+
byte led_pins[] = {2, 3, 4, 5, 6, 7, 8, 9}; // Pins for LEDs
47+
byte i;
4748

4849
void setup() {
4950

@@ -55,17 +56,39 @@ void setup() {
5556

5657
void loop() {
5758

58-
// Draw a line
59-
//Plex.line(1, 1, 2, 5);
60-
//Plex.display();
59+
// Draw a dot (x, y)
60+
Plex.clear();
61+
Plex.pixel(1, 2);
62+
Plex.display();
63+
delay(1000);
64+
65+
// Draw a line (x0, y0, y1, y1)
66+
Plex.clear();
67+
Plex.line(1, 2, 5, 5);
68+
Plex.display();
69+
delay(1000);
70+
71+
// Draw a rectangle (x, y, width, height)
72+
Plex.clear();
73+
Plex.rect(1, 2, 5, 4);
74+
Plex.display();
75+
delay(1000);
76+
77+
// Draw a filled rectangle (x, y, width, height)
78+
Plex.clear();
79+
Plex.rectFill(1, 2, 5, 4);
80+
Plex.display();
81+
delay(1000);
6182

62-
// Draw a rectangle
63-
for ( int i = 0; i < 9; i++ ) {
64-
Plex.clear();
65-
Plex.rect(1, 1, i, i);
66-
Plex.display();
67-
delay(100);
68-
}
83+
// Draw a circle (x, y, radius)
84+
Plex.clear();
85+
Plex.circle(3, 3, 3);
86+
Plex.display();
87+
delay(1000);
6988

89+
// Draw a filled circle (x, y, radius)
90+
Plex.clear();
91+
Plex.circleFill(3, 3, 3);
92+
Plex.display();
7093
delay(1000);
7194
}

Libraries/SparkFun_LED_8x7/examples/ScrollText/ScrollText.ino

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,12 @@ Distributed as-is; no warranty is given.
4141

4242
#include <SparkFun_LED_8x7.h>
4343
#include <Chaplex.h>
44-
#include <MemoryFree.h>
4544

4645
// Global variables
47-
static byte led_pins[] = {9,8,7,6,5,4,3,2}; // Pins for LEDs
46+
static byte led_pins[] = {2, 3, 4, 5, 6, 7, 8, 9}; // Pins for LEDs
4847

4948
void setup() {
5049

51-
// Initialize Serial port for debugging
52-
Serial.begin(9600);
53-
Serial.println();
54-
Serial.println(F("------------------------------"));
55-
Serial.println(F("SparkFun LED 8x7 - Scroll Text"));
56-
Serial.println(F("------------------------------"));
57-
5850
// Initialize LED array
5951
Plex.init(led_pins);
6052

@@ -65,14 +57,13 @@ void setup() {
6557

6658
void loop() {
6759

68-
Serial.print("RAM: ");
69-
Serial.println(freeMemory());
60+
// Scroll text 2 times
61+
Plex.scrollText("Hello. :)", 2);
62+
delay(12000);
7063

71-
// Scroll some text then stop
72-
delay(2000);
73-
Plex.scrollText("Testz!", 1);
64+
// Scroll text until we stop it
65+
Plex.scrollText("Let's scroll!");
7466
delay(10000);
75-
Plex.scrollText("Bum.");
76-
//Plex.stopScrolling();
77-
delay(2000);
67+
Plex.stopScrolling();
68+
delay(1000);
7869
}

0 commit comments

Comments
 (0)