Welcome, Guest
Username: Password: Remember me

TOPIC: Code to Check the Arduino Audio Meter Build

Code to Check the Arduino Audio Meter Build 4 months 2 weeks ago #1853

  • Ray
  • Ray's Avatar
  • NOW ONLINE
  • Moderator
  • Posts: 695
  • Thank you received: 146
  • Karma: 41
This simple code will help you to debug any problems with the hardware.
You would need to install the EnableInterrupt library using Tools/Manage Libraries.. and search for "EnableInterrupt"
  • The LED matrices will go ON or OFF depending if you go clockwise/anticlockwise with the encoder
  • With the serial monitor you will read the encoder counter and the push button
  • you can enable the "Serial.println(analogRead(A0));" line and read the analog signal coming into the pedal. The default value should be around 1024/2=512 (I read 402 in mine)
//This is a short code that tests all the systems in the Arduino Audio Meter
//You would need to install the library EnableInterrupt using Tools/Manage Libraries.. and search for "EnableInterrupt"
//The LED matrices will go ON or OFF depending if you go clockwise/anticockwise with the encoder
//and in the serial monitor you will read the encoder counter and the push button
//you can enable the Serial.println(analogRead(A0)); Line and the default value should be around 1024/2=512 (I read 402 in mine)
 
#include <EnableInterrupt.h>
#include "LedControl.h"

//init the LedControl
LedControl lc = LedControl(12, 11, 10, 4);
 
//define Arduino Pins used
#define ENCODER_A A4
#define ENCODER_B A3
#define ENCODER_GND A5
#define ENCODER_PUSH A2

//Variables needed
int counter = 0; 
int aState;
int aLastState; 
 
void setup() {
 
//initialice the 4 LED matrices:
lc.shutdown(0, false);  // turns on display
lc.setIntensity(0, 8); // 15 = brightest
lc.clearDisplay(0);
 
lc.shutdown(1, false);  // turns on display
lc.setIntensity(1, 8); // 15 = brightest
lc.clearDisplay(1);
 
lc.shutdown(2, false);  // turns on display
lc.setIntensity(2, 8); // 15 = brightest
lc.clearDisplay(2);
 
lc.shutdown(3, false);  // turns on display
lc.setIntensity(3, 8); // 15 = brightest
lc.clearDisplay(3);
 
//init the Arduino Pins used
pinMode (ENCODER_A,INPUT_PULLUP);
pinMode (ENCODER_B,INPUT_PULLUP);
pinMode (ENCODER_PUSH,INPUT_PULLUP);
pinMode (ENCODER_GND,OUTPUT);
 
//this is needed for the encoder to work
aLastState = digitalRead(ENCODER_A);   
digitalWrite(ENCODER_GND, LOW);
enableInterrupt(ENCODER_A, interruptFunction, CHANGE);
enableInterrupt(ENCODER_B, interruptFunction, CHANGE);
 
//init the serial port  
Serial.begin(9600);
}
 
void loop() 
{
//print "Botton Pushed" when pushed   
if (digitalRead(ENCODER_PUSH) == LOW) {Serial.println("Botton Pushed");} 
 
//you can enable this A0 audio signal reading, you should read a value around 400 
//Serial.println(analogRead(A0));    
}
 
 
//Interrup Function for the Encoder
void interruptFunction() 
{
 
   aState = digitalRead(ENCODER_A); // Reads the "current" state of the outputA
   // If the previous and the current state of the outputA are different, that means a Pulse has occured
   if (aState != aLastState){     
     // If the outputB state is different to the outputA state, that means the encoder is rotating clockwise
     if (digitalRead(ENCODER_B) != aState) 
     { 
counter++;
        for(int j = 0; j < 8; j++)
        {
            lc.setColumn(0, j, 0); //LED matrix 1 turn OFF column
            lc.setColumn(1, j, 0); //LED matrix 2 turn OFF column
            lc.setColumn(2, j, 0); //LED matrix 3 turn OFF column
            lc.setColumn(3, j, 0); //LED matrix 4 turn OFF column         
        }
     } 
     else 
     {
counter--;
        for(int j = 0; j < 8; j++)
        {
            lc.setColumn(0, j, 0xFF); //LED matrix 1 set colum to all ON (FF)
            lc.setColumn(1, j, 0xFF); //LED matrix 2 set colum to all ON (FF)
            lc.setColumn(2, j, 0xFF); //LED matrix 3 set colum to all ON (FF)
            lc.setColumn(3, j, 0xFF); //LED matrix 4 set colum to all ON (FF)      
        }
     } 
   } 
   aLastState = aState; // Updates the previous state of the outputA with the current state
Serial.print("Encoder Value");
Serial.println(counter);
}
 
 
The complete code with libraries:
[attachment=547]Arduino-Audio-Meter-Checker.zip[/attachment]
 
Attachments:
The administrator has disabled public write access.
Time to create page: 0.264 seconds
Powered by Kunena Forum
Joomla SEF URLs by Artio