fezder
Well-Known Member
Right, so far i've managed to create with your help scrolling display, as well as many other things. Recently i learned that array can be used also to store data from ADC. But, what i'm now trying to create (seems my brains need constantly something new to be learned....) is that 8x8 matrix would show data from ADC in timelapse, like take reading from ADC->store in array one by one-> display in matrix one by one (in either bar or dot mode,). What makes it also hardish, is that value will change all the time, so effect would look roughly same like in roll-mode on oscilloscope.
Stuff, bits'n pieces i have so far:
First code i have taking data and storing it in array
Then code i can use for creating bar/dot graph in matrix
and lastly, code for scrolling
I have feeling that switch case is needed to change that value from array used for storing ADC data, but again, help would be great! or hints/clues, just trying to learn and making something useful on way . And still using chained 74595 shift registers, two pieces in this circuit, plus darlington array for columns
Stuff, bits'n pieces i have so far:
First code i have taking data and storing it in array
C:
const unsigned int numReadings = 8; //matrix is 8-wide
unsigned int analogvals[numReadings]; //array where to store 8-readings from ADC
unsigned int i = 0;
void setup()
{
Serial.begin(9600); //open serial
}
void loop()
{
analogvals[i] = analogRead(A0);
i++;
if (i>=numReadings)
{
i=0; //reset to beginning of array, so you don't try to save readings outside of the bounds of the array
}
delay(100); //wait 1 sec //from here on, print values from array one by one when called
Serial.println(analogvals[0]);
delay(100); //wait 1 sec
Serial.println(analogvals[1]);
delay(100); //wait 1 sec
Serial.println(analogvals[2]);
delay(100); //wait 1 sec
Serial.println(analogvals[3]);
delay(100); //wait 1 sec
Serial.println(analogvals[4]);
delay(100); //wait 1 sec
Serial.println(analogvals[5]);
delay(100); //wait 1 sec
Serial.println(analogvals[6]);
delay(100); //wait 1 sec
Serial.println(analogvals[7]);
}
Then code i can use for creating bar/dot graph in matrix
C:
int dataPin = 2; // ic: 14, ser_in Define which pins will be used for the Shift Register control
int latchPin = 3; // ic:12 silkscreen numbers!
int clockPin = 4; // ic:11
int i = 0;
//OE-GND (PIN 13)
//MR-VCC (PIN 10)
byte mappedValue[9] = {0, 1, 3, 7, 15, 31, 63, 127}; //bar mode
byte mappedValue2[9] = {0, 1, 2, 4, 8, 16, 32, 64, 127}; //dot mode
void setup()
{
DDRD = DDRD | B11111100; //port registers used to set pin directions
}
void loop()
{
i++;
if (i >= 8)
{
i = 0; //so bits aren't losed
}
int j = map( analogRead (A0), 0, 1023, 0, 8 ); //read and map
j = mappedValue[j]; //convert mapped value to byte array
PORTD = B00001000; //close latch pin
shiftOut(dataPin, clockPin, MSBFIRST, 1<<i); //only one column active at a time
shiftOut(dataPin, clockPin, MSBFIRST, j); //draw bars
PORTD = B00000000; //open latch pin
}
and lastly, code for scrolling
C:
int dataPin = 2; //IC 14 //Define which pins will be used for the Shift Register control
int latchPin = 3; //IC 12
int clockPin = 4; //IC 11
//OE-GND
//MR-VCC
int delaytime = 1, timer, timerPrev = 0;
int shift = 0;
int len = 32;
static uint8_t x [32] =
{
B00000000,
B00000000,
B01111110,
B00001000,
B01111110,
B00000000,
B01111110,
B01001010,
B01000010,
B00000000,
B01111110,
B00000010,
B00000000,
B01111110,
B00000010,
B00000000,
B00111100,
B01000010,
B00111100,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
};
void setup()
{
DDRD = DDRD | B00011100; //set pins as output
}
void loop()
{
timer = millis ();
if (timer-timerPrev >100)
{
shift++;
if(shift==len)shift=0;
timerPrev=timer;
}
for(int i=0; i<8; i++)
{
PORTD = B00000000; //turn latch low
shiftOut(dataPin, clockPin, MSBFIRST, 1 << i); //Send the data #2 (what columns to power)
shiftOut(dataPin, clockPin, LSBFIRST, x[i+shift > len-1 ? i+shift-len : i+shift]); //Send the data #1 ( what data to draw)
PORTD = B00001000; //turn latch on->show screen
delayMicroseconds (1000);
}
}
Last edited: