The problem is you're reading outside the bounds of screen
. Screen has valid addresses of 0-7, and you're trying to read from screen[8][n]
.
8
887|22021|-15872|-30720|124|2|9|10
^ How can you have line "8"? The line number is Serial.println(i-1);
, and the value is Serial.print(screen[i-1][0]);
, so the error will be present in the array access as well. To fix it, you just need to change to screen[i-2]
.
Ok, the other corruption (6
0|0|0|0|0|0|Á
) issue is because you're heavily oversaturating the serial port. I stuck a 1 second delay in after each loop, and it fixed that issue.
Change:
void loop() {
static int display [8][8] = {
{1,0,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0},
{0,0,1,0,0,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,0,1,0,0,0},
{0,0,0,0,0,1,0,0},
{0,0,0,0,0,0,1,0},
{0,0,0,0,0,0,0,1}
};
updateScreen(display);
delay(1000); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
}
or
void updateScreen(int screen[8][8]) {
Serial.begin(115200);
int i;
<snip>
Output:
0
1|0|0|0|0|0|0|0
1
0|1|0|0|0|0|0|0
2
0|0|1|0|0|0|0|0
3
0|0|0|1|0|0|0|0
4
0|0|0|0|1|0|0|0
5
0|0|0|0|0|1|0|0
6
0|0|0|0|0|0|1|0
7
0|0|0|0|0|0|0|1
I also tried simply increasing the baud-rate (to 115200
baud), and that also fixed the issue without the delay, so either option would work.
You've saturated the input (SIG, pin 5) above the reference voltage (Rhi, pin 6). That's why the only the topmost LED flickers in dot mode and all LEDs are on in bar mode.
If you look at the SF schematic, they've connected a direct adjustable DC source to pin 5, whereas you're connecting an audio source that could be:
(a) far too loud (turn it down!), or;
(b) carrying a DC offset which is far above the refernce voltage of "3.4V".
My guess it scenario (b). If the audio source is your PC soundcard, and you're powering the 3915 from an Arduino board which is in turn powered by the same PC's USB power, you can't guarantee the audio 'ground' is the same as the 3915 'ground'. Even if you've connected the 3.5mm jack to ground, you could still have a bad time.
The solution is to put a nice big resistor in parallel with the jack's ring/tip and the 3915 ground - 1Meg will do (or the nearest you have available) and then put a capacitor (1uF) between the jack and pin 5:
simulate this circuit – Schematic created using CircuitLab
The 1M resistor offers some impedance for the capacitor to work against and helps tie the audio signal to a better reference, and the capacitor will remove the DC offset present in the audio signal. The input impedance of the 3915 is 20k (and 12k for the 3916), so you might need to fine-tune the cap value to get a better low-frequency cut off. Ideally you should be running the audio signal through at least a rectifier, if not a proper peak detector. It may be a little too much, but you get a much better visual effect. All manner of rectifiers can be found in the 3915's datasheet, and the 3916 goes that bit further with genuine-specification VU-meter circuits.
If that still doesn't help, you'll just have to 'manually' reduce the input voltage (between the cap and pin 5) with a simple voltage divider. Check what kind of voltage is there with a multimeter if you can first, or just stick with trial and error.
Best Answer
It's a simulation model misbehavior, you should add pull up resistors to the outputs (for the simulation only) to correct it.
The shown schematic is valid for simulation only, the pullup network is not needed in the real circuit.
You also have to add the current limiting series resistors for the leds of the dot display in the real circui, they are omitted in proteus to improve the simulation speed.