We've been playing with the code a bit more, as well as making a little progress with setting up the hardware. Thanks to the good folks at Metrix Create:Space, we realized that the way we had decided to set up our hardware was a little ridiculous. We were going to use a LED driver to make a 7-segment display, but Richard of MC:_ informed us that 7-segment drivers exist and do the work for you! Awesome! We will be using SN7447s, and we are in the process of figuring out how to wire everything.
We simplified, then modified our code to be able to count the number of tweets that are received, once the appropriate processing sketch is running. The LED in pin 13 blinks the number of tweets received; e.g., for 5 tweets received, it blinks 5 times. Here is the Arduino code for counting the number of tweets (used in conjunction with the processing sketch in the last post we made):
void listenToSerial()
{
int serialMsg = 0;
if (Serial.available())
{
serialMsg = Serial.read();
if (serialMsg == 1)
{
tweetCount++;
for (int g=0; g<tweetCount; g++)
{
digitalWrite (LED13, HIGH); //LED in pin 13 blinks the number of tweets received
delay (500);
digitalWrite (LED13, LOW);
delay (500);
}
}
}
else
{
digitalWrite (LED13, HIGH); //in the normal state (no tweets received),
// LED in pin 13 stays lighted
delay (3000);
}
}
Our next step (code-wise) will be to figure out how to use this code with the SN7447 drivers to create numbers. Once we have it wired, I think it will be a matter of setting the correct Arduino pins HIGH or LOW. From what we understand from the SN7447 datasheet found here, there are 4 inputs (A, B, C, and D, or specifically on the SN7447: pins 7, 1, 2, and 6), for which we use binary code to control the a-g outputs of the 7-segment display. We'll try out a few more things and keep you posted on our progress!
EDIT:
Got it to work!
We used the setup from this schematic diagram, and connected everything appropriately. We then used a slight variation on the code from this post, to test whether the setup was working properly. Took a few tries (tweaks in the code, changes in the wiring) to get the numbers to count up correctly. We then combined the code shown above with the code from the forum post to link the counting code with the twitter-interactive code. It took a while to figure it all out, but in the end, the code is actually pretty simple:
int seven_seg_digits[10][4] = { { 0,0,0,0 }, // = 0
{ 0,0,0,1 }, // = 1
{ 0,0,1,0 }, // = 2
{ 0,0,1,1 }, // = 3
{ 0,1,0,0 }, // = 4
{ 0,1,0,1 }, // = 5
{ 0,1,1,0 }, // = 6
{ 0,1,1,1 }, // = 7
{ 1,0,0,0 }, // = 8
{ 1,0,0,1 } // = 9
};
int tweetCount = 0;
void setup()
{
Serial.begin(9600);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
}
void loop()
{
listenToSerial();
}
void listenToSerial()
{
int serialMsg = 0;
if (Serial.available())
{
serialMsg = Serial.read();
if (serialMsg == 1)
{
Display();
}
}
}
void Display()
{
tweetCount++;
int ones = 0;
int tens = 0;
ones = tweetCount % 10;
tens = tweetCount / 10;
int pinOnes = 6;
for (int disp1 = 0; disp1 < 4; disp1++)
{
digitalWrite(pinOnes, seven_seg_digits[ones][disp1]);
++ pinOnes;
}
int pinTens = 10;
for (int disp10 = 0; disp10 < 4; disp10++)
{
digitalWrite(pinTens, seven_seg_digits[tens][disp10]);
++ pinTens;
}
}
Here's a photo of the setup:
With the code working, mainly all that's left to do is to make the actual LED number display board by soldering bunch of of LEDs and resistors together (in the groupings of the a-g segments).
No comments:
Post a Comment