Hello I am trying to manipulate the code from this adafruit instructional for myself (Overview | Adafruit Microphone Amplifier Breakout | Adafruit Learning System).
The only difference is, instead of me using an 8x8 bicolor led matrix, I am using a 8x16 single color matrix (16x8 1.2 LED Matrix + Backpack - Ultra Bright Square Green LEDs : ID 2042 : $16.95 : Adafruit Industries, Unique & fun DIY electronics and kits). I understand I need to change the call from "Adafruit_BicolorMatrix matrix = Adafruit_BicolorMatrix();" to "Adafruit_8x16matrix matrix = Adafruit_8x16matrix();" however, what else in the code do I need to change to make this scrolling sound meter led display work so that theres 8 rows and 16 columns. I have also attached the general code below:
/****************************************
Scrolling Sound Meter Sketch for the
Adafruit Microphone Amplifier
****************************************/
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
// Include the Matrix code for display
Adafruit_8x16matrix matrix = Adafruit_8x16matrix();
//replaced from: "Adafruit_BicolorMatrix matrix = Adafruit_BicolorMatrix();"
const int maxScale = 8;
const int redZone = 5;
const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
unsigned int sample;
void setup()
{
Serial.begin(9600);
matrix.begin(0x70); // pass in the address
}
void loop()
{
unsigned long startMillis= millis(); // Start of sample window
unsigned int peakToPeak = 0; // peak-to-peak level
unsigned int signalMax = 0;
unsigned int signalMin = 1024;
while (millis() - startMillis < sampleWindow)
{
sample = analogRead(0);
if (sample < 1024) // toss out spurious readings
{
if (sample > signalMax)
{
signalMax = sample; // save just the max levels
}
else if (sample < signalMin)
{
signalMin = sample; // save just the min levels
}
}
}
peakToPeak = signalMax - signalMin;
// map 1v p-p level to the max scale of the display
int displayPeak = map(peakToPeak, 0, 1023, 0, maxScale);
// Update the display:
for (int i = 0; i < 7; i++) // shift the display left
{
matrix.displaybuffer[i] = matrix.displaybuffer[i+1];
}
// draw the new sample
for (int i = 0; i <= maxScale; i++)
{
if (i >= displayPeak) // blank these pixels
{
matrix.drawPixel(i, 7, 0);
}
else if (i < redZone) // draw in green
{
matrix.drawPixel(i, 7, LED_GREEN);
}
else // Red Alert! Red Alert!
{
matrix.drawPixel(i, 7, LED_RED);
}
}
matrix.writeDisplay(); // write the changes we just made to the display
}