rubbish, let's go retro. I always liked those little LED bubble displays growing up so how about those?
That means: current sourced to A1-A8 light up segments of the LEDs in a single bubble, which are laid out like this:
OK with that super basic knowledge under my belt, it was time to see if anyone had already written up an easy way to hook 7 segment displays up to Arduino type MPUs. Why reinvent the wheel?
OK, let's motorize this pursuit.....
OK how about the code? Here is what I was using to get the pot to go--I wrote other variations to try out other things, comment if anyone wants to see those.
This wasn't too hard--it took a couple of evenings. I got stuck for maybe an hour on one strange thing--the bubbles wouldn't work reliably if I was using Serial.write to debug. Commenting the serial stuff out, the bubbles worked again. So I was introducing a bug by debugging? A pest, but yes.
A few >'s instead needed to be <' s but overall, not bad at all.
//////////******************************
long testnumber = 0;
//testnumber is what I want to show up on the NSA1166.
//you have to use long. int only goes to 32000 or something close!
//////////******************************
unsigned long startMillis; //start millis timer
unsigned long currentMillis;
const unsigned long period = 10;
//each item in the array below ground a given pin of a 595, so the Bubble can display.
int mybubble[] = {124,188,220,236,244,248};
int c = 0; /* used to hold number of elements in the array */
long n;
int p = 0; // counter for filling array with elements.
int numberArray[6];
//this holds each value of number we are trying to display
// bubble zero is leftmost bubble!
long bubble5 = 0;
long bubble4 = 0;
long bubble3 = 0;
long bubble2 = 0;
long bubble1 = 0;
long bubble0 = 0;
//pins used to feed shift regs
//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;
//pot wiper connected to A0. gnd AND 5V for the rest
int pot = A0;
void setup() {
// put your setup code here, to run once:
//set pins to output so you can control the shift register
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
// debug using serial
//Serial.begin(9600);
// BE CAREFUL serial stuff can step on Bubble display and make it mysteriously not work.
// initialize array
numberArray[0] = 0;
numberArray[1] = 0;
numberArray[2] = 0;
numberArray[3] = 0;
numberArray[4] = 0;
numberArray[5] = 0;
}
void loop()
{
//do a analog read every 10ms
currentMillis = millis();
if (currentMillis - startMillis >= period) //test whether the period has elapsed
{
testnumber = analogRead(pot);
startMillis = currentMillis;
}
c = 0;
// turn that number into an array. Note: ARRAY is backwards!
//first we need to determine how many digits the number in ques\ton has. We need that to send //blanks out later
n = testnumber;
while (n != 0)
{
n /= 10;
c++;
}
/* Serial.println("testnumber variable value is: ");
Serial.println(testnumber);
Serial.println("length of array is: ");
Serial.println(c);
*/
/////////////////
n = testnumber;
p = 5;
//now fill an array with each digit.
while ((p > -1) && (n != 0))
{
numberArray[p] = n % 10;
n /= 10;
/*
Serial.print("----------");
Serial.println("We are seeing output of array value");
Serial.println(p);
Serial.println(numberArray[p]);
Serial.println("");
*/
p--;
}
//wanted to time more CRAP then realized it wasn't needed, comment that!
//Leaving it here in case I remember what I was thinking.
////currentMillis = millis();
//if (currentMillis - startMillis >= period) //test whether the period has elapsed
//{
//startMillis = currentMillis; //update current millis.
/////////////////////////////////////////////////
//YEH next part can be simplified and made into a single function.
//I am too lazy to do this. you do it!
//AND--I don't accommodate decimal points at all.
//Again I am too lazy.....
////////////////////////////////////////////
bubble5 = getbyte(numberArray[5]);
//write to shift reg. rightmost digit.
// take the latchPin low so
// the LEDs don't change while you're sending in bits:
digitalWrite(latchPin, LOW);
// next line puts numeric data onto shift register
shiftOut(dataPin, clockPin, LSBFIRST, bubble5);
// then pick which bubble to impact
shiftOut(dataPin, clockPin, LSBFIRST, mybubble[5]);
//take the latch pin high so the LEDs will light up:
digitalWrite(latchPin, HIGH);
//write to shift reg digit. 2nd from right
if (c < 2)
{
bubble4 = 0;
}
else
{
bubble4 = getbyte(numberArray[4]);
}
// take the latchPin low so
// the LEDs don't change while you're sending in bits:
digitalWrite(latchPin, LOW);
// next line puts numeric data onto shift register
shiftOut(dataPin, clockPin, LSBFIRST, bubble4);
// then pick which bubble to impact
shiftOut(dataPin, clockPin, LSBFIRST, mybubble[4]);
//take the latch pin high so the LEDs will light up:
digitalWrite(latchPin, HIGH);
//write to shift reg digit. 3rd from right
if (c < 3)
{
bubble3 = 0;
}
else
{
bubble3 = getbyte(numberArray[3]);
}
// take the latchPin low so
// the LEDs don't change while you're sending in bits:
digitalWrite(latchPin, LOW);
// next line puts numeric data onto shift register
shiftOut(dataPin, clockPin, LSBFIRST, bubble3);
// then pick which bubble to impact
shiftOut(dataPin, clockPin, LSBFIRST, mybubble[3]);
//take the latch pin high so the LEDs will light up:
digitalWrite(latchPin, HIGH);
//write to shift reg digit. 4th from right
if (c < 4)
{
bubble2 = 0;
}
else
{
bubble2 = getbyte(numberArray[2]);
}
// take the latchPin low so
// the LEDs don't change while you're sending in bits:
digitalWrite(latchPin, LOW);
// next line puts numeric data onto shift register
shiftOut(dataPin, clockPin, LSBFIRST, bubble2);
// then pick which bubble to impact
shiftOut(dataPin, clockPin, LSBFIRST, mybubble[2]);
//take the latch pin high so the LEDs will light up:
digitalWrite(latchPin, HIGH);
//write to shift reg digit. 5th from right
if (c < 5)
{
bubble1 = 0;
}
else
{
bubble1 = getbyte(numberArray[1]);
}
// take the latchPin low so
// the LEDs don't change while you're sending in bits:
digitalWrite(latchPin, LOW);
// next line puts numeric data onto shift register
shiftOut(dataPin, clockPin, LSBFIRST, bubble1);
// then pick which bubble to impact
shiftOut(dataPin, clockPin, LSBFIRST, mybubble[1]);
//take the latch pin high so the LEDs will light up:
digitalWrite(latchPin, HIGH);
//write to shift reg digit. leftmost
if (c < 6)
{
bubble0 = 0;
}
else
{
bubble0 = getbyte(numberArray[0]);
}
// take the latchPin low so
// the LEDs don't change while you're sending in bits:
digitalWrite(latchPin, LOW);
// next line puts numeric data onto shift register
shiftOut(dataPin, clockPin, LSBFIRST, bubble0);
// then pick which bubble to impact
shiftOut(dataPin, clockPin, LSBFIRST, mybubble[0]);
//take the latch pin high so the LEDs will light up:
digitalWrite(latchPin, HIGH);
} // end main loop
//shiftOUT does not seem to accommodate bxxxxxxx typle format?
//whatever, I am using decimal values for this.
byte getbyte(long x)
{
int a;
if (x == 0)
{
a = 252; //11111100
return a;
}
if (x == 1)
{
a = 96; //011000000
return a;
}
if (x == 2)
{
a = 218; //11011010
return a;
}
if (x == 3)
{
a = 242; //11110010
return a;
}
if (x == 4)
{
a = 102; //01100110
return a;
}
if (x == 5)
{
a = 182; //10110110
return a;
}
if (x == 6)
{
a = 190 ; //10111110
return a;
}
if (x == 7)
{
a = 224; //11100000
return a;
}
if (x == 8)
{
a = 254 ; //11111110
return a;
}
if (x == 9)
{
a = 230 ; //11100110
return a;
}
}
Also, would be nice to get decimals going, but I don't have an immediate need for that, so for now, wah-wah.
That's it, no smoke, no fumes, bubble up the covid and leave it behind!