Welcome, Guest
Username: Password: Remember me

TOPIC: VUmeter on a OLED 128x64 (I2C)

VUmeter on a OLED 128x64 (I2C) 9 months 3 weeks ago #1234

  • Ray
  • Ray's Avatar
  • OFFLINE
  • Platinum Member
  • Posts: 532
  • Thank you received: 116
  • Karma: 27
This is a short tutorial to simulate an analog VUmeter on a 128x64 OLED display, using I2C communication and U8glib Libraries:

sonyvumeter.jpg


Before starting, make sure that you have installed and working the U8gLib libraries, there is a topic covering that.

The idea is simple, the vu meter image is an image rendered on the background and the needle is a line which is adjusted following a variable.
The image rendered on the background is a 128x64 bitmap:

File Attachment:

File Name: VU_meter_128x64.zip
File Size: 1 KB


Most of the area is empty ("white"), so it is better to use a resized image which is 128x36 but contains all the info, the code will be smaller:

File Attachment:

File Name: VU_meter_128x36.zip
File Size: 0 KB



To translate the images from BMP to HEX (which is what you need to include in your code) you would need the LCD Assistant, here is a nice tutorial about it, but it is pretty simple:
  1. Save the image you want to use with Microsoft Paint (you can also use Gimp) as a "Monochrome Bitmap" *.bmp, make sure that the image is 128x64 or smaller
  2. Open the LCD assistant and using the options that you can see below generate the output txt file
You can download the LCD assistant software from here:

File Attachment:

File Name: LCDAssistant.zip
File Size: 422 KB


lcdassistant.png


IMPORTANT: The table/variable generated has to be used in the code as:
const uint8_t VARIABLE_NAME[] U8G_PROGMEM ={...};
The LCD assistant automatically calls this variable:
const unsigned char VARIABLE_NAME [] = {...};
And it does not work.

This first simple code just "paints" the vu meter image, using the u8g.drawBitmapP function:
#include "U8glib.h"
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NO_ACK);  // Display which does not send ACK
 
//defining harware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4

//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel

//other variables
int input, distortion_threshold=6000; //initial value adjusted by try and error.
int counter=0;
unsigned int ADC_low, ADC_high;
 
const uint8_t rook_bitmap[] U8G_PROGMEM = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x03, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xE0, 0x12, 0x04, 0x80, 0x10, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x19, 0xC0, 0x20, 0x0C, 0x03, 0x80, 0x10, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0A, 0x20, 0x40, 0x12, 0x00, 0x80, 0x10, 0x48, 0x00, 0x70, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0A, 0x20, 0x40, 0x0C, 0x03, 0x00, 0x10, 0x30, 0x00, 0x08, 0x00, 0x00, 0x00,
0x00, 0x1C, 0x30, 0x0A, 0x20, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x00, 0x02, 0x48, 0x09, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0xF0, 0x00,
0x00, 0x0E, 0x48, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x20, 0x20, 0x00, 0x70, 0x00, 0x80, 0x00,
0x00, 0x10, 0x48, 0x00, 0x00, 0x20, 0x04, 0x01, 0x08, 0x20, 0x20, 0x00, 0x00, 0x00, 0xE0, 0x00,
0x00, 0x1E, 0x30, 0x00, 0x20, 0x20, 0x04, 0x01, 0x08, 0x40, 0x44, 0x00, 0x00, 0x00, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x04, 0x01, 0x08, 0x40, 0x44, 0x20, 0x40, 0x00, 0xE0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x04, 0x01, 0x08, 0x40, 0x48, 0x20, 0x40, 0x00, 0x00, 0x10,
0x00, 0x00, 0x10, 0x40, 0x10, 0x10, 0x1F, 0xFF, 0xFF, 0xE0, 0xF8, 0x40, 0x40, 0x00, 0x00, 0x10,
0x00, 0x00, 0x18, 0x20, 0x08, 0x1F, 0xE0, 0x00, 0x00, 0x1F, 0xFF, 0xC0, 0x84, 0x03, 0x00, 0x10,
0x7F, 0x80, 0x0C, 0x20, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFC, 0x84, 0x04, 0x00, 0xFE,
0x00, 0x00, 0x04, 0x11, 0xF0, 0x00, 0x08, 0x00, 0x80, 0x00, 0x1F, 0xFF, 0xE8, 0x04, 0x00, 0x10,
0x00, 0x00, 0x66, 0x1E, 0x00, 0x00, 0x08, 0x00, 0x80, 0x03, 0x00, 0x3F, 0xFC, 0x08, 0x00, 0x10,
0x00, 0x01, 0xE3, 0xE0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0xFF, 0xD0, 0x00, 0x10,
0x00, 0x01, 0xFE, 0x00, 0x02, 0x00, 0x76, 0x07, 0x60, 0x00, 0x00, 0x00, 0x1F, 0xF8, 0x00, 0x00,
0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x69, 0x81, 0x90, 0x67, 0x30, 0x00, 0x03, 0xFF, 0x00, 0x00,
0x00, 0x03, 0x80, 0x00, 0x19, 0xC0, 0x19, 0x82, 0x90, 0x28, 0xC8, 0x00, 0x00, 0x3F, 0xE0, 0x00,
0x00, 0x1C, 0x08, 0x00, 0x06, 0x20, 0x76, 0x02, 0x60, 0x28, 0xC8, 0x00, 0x00, 0x07, 0xF8, 0x00,
0x00, 0x60, 0x04, 0x00, 0x0E, 0x20, 0x00, 0x00, 0x00, 0x27, 0x30, 0x00, 0x00, 0x00, 0xFF, 0x00,
0x03, 0x80, 0x00, 0x00, 0x19, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xC0,
0x04, 0x00, 0x01, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xF8,
0x18, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0,
0x00, 0x10, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
0x00, 0x28, 0x01, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x11, 0x80, 0x00, 0x00, 0x00, 0x04, 0x02, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x03, 0x8C, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x01, 0xD8, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0xA0, 0x00, 0x00, 0x00, 0x00, 0x70, 0x18, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x20, 0x0F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
 
void draw(void) {
  // graphic commands to redraw the complete screen should be placed here  
  u8g.drawBitmapP( 0, 0,16,36, rook_bitmap);
}
 
void setup(void) {
}
 
void loop(void) {
  // picture loop
  u8g.firstPage();  
  do {
    draw();
  } while( u8g.nextPage() );
 
  // rebuild the picture after some delay
  delay(1000);
}

This second code, includes a line that moves automatically from left to right using the function u8g.drawLine(Xorigin,Yorigin,Xend, Yend);
so u8g.drawLine(64,60,counter, 10); will draw an arrow that goes from 64, 60 to X,10
// CC-by-NC-www.Electrosmash.com/rights
// Based on OpenMusicLabs previous works.
// pedalshield_mega_distortion.ino reads the ADC signal and clip it to a threshold value
// pressing the pushbutton_1 or 2 turns the distortion harder or softer.
 
#include "U8glib.h"
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NO_ACK);  // Display which does not send ACK
 
//defining harware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4

//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel

//other variables
int input, distortion_threshold=6000; //initial value adjusted by try and error.
int counter=0;
unsigned int ADC_low, ADC_high;
 
const uint8_t rook_bitmap[] U8G_PROGMEM = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x03, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xE0, 0x12, 0x04, 0x80, 0x10, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x19, 0xC0, 0x20, 0x0C, 0x03, 0x80, 0x10, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0A, 0x20, 0x40, 0x12, 0x00, 0x80, 0x10, 0x48, 0x00, 0x70, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0A, 0x20, 0x40, 0x0C, 0x03, 0x00, 0x10, 0x30, 0x00, 0x08, 0x00, 0x00, 0x00,
0x00, 0x1C, 0x30, 0x0A, 0x20, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x00, 0x02, 0x48, 0x09, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0xF0, 0x00,
0x00, 0x0E, 0x48, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x20, 0x20, 0x00, 0x70, 0x00, 0x80, 0x00,
0x00, 0x10, 0x48, 0x00, 0x00, 0x20, 0x04, 0x01, 0x08, 0x20, 0x20, 0x00, 0x00, 0x00, 0xE0, 0x00,
0x00, 0x1E, 0x30, 0x00, 0x20, 0x20, 0x04, 0x01, 0x08, 0x40, 0x44, 0x00, 0x00, 0x00, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x04, 0x01, 0x08, 0x40, 0x44, 0x20, 0x40, 0x00, 0xE0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x04, 0x01, 0x08, 0x40, 0x48, 0x20, 0x40, 0x00, 0x00, 0x10,
0x00, 0x00, 0x10, 0x40, 0x10, 0x10, 0x1F, 0xFF, 0xFF, 0xE0, 0xF8, 0x40, 0x40, 0x00, 0x00, 0x10,
0x00, 0x00, 0x18, 0x20, 0x08, 0x1F, 0xE0, 0x00, 0x00, 0x1F, 0xFF, 0xC0, 0x84, 0x03, 0x00, 0x10,
0x7F, 0x80, 0x0C, 0x20, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFC, 0x84, 0x04, 0x00, 0xFE,
0x00, 0x00, 0x04, 0x11, 0xF0, 0x00, 0x08, 0x00, 0x80, 0x00, 0x1F, 0xFF, 0xE8, 0x04, 0x00, 0x10,
0x00, 0x00, 0x66, 0x1E, 0x00, 0x00, 0x08, 0x00, 0x80, 0x03, 0x00, 0x3F, 0xFC, 0x08, 0x00, 0x10,
0x00, 0x01, 0xE3, 0xE0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0xFF, 0xD0, 0x00, 0x10,
0x00, 0x01, 0xFE, 0x00, 0x02, 0x00, 0x76, 0x07, 0x60, 0x00, 0x00, 0x00, 0x1F, 0xF8, 0x00, 0x00,
0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x69, 0x81, 0x90, 0x67, 0x30, 0x00, 0x03, 0xFF, 0x00, 0x00,
0x00, 0x03, 0x80, 0x00, 0x19, 0xC0, 0x19, 0x82, 0x90, 0x28, 0xC8, 0x00, 0x00, 0x3F, 0xE0, 0x00,
0x00, 0x1C, 0x08, 0x00, 0x06, 0x20, 0x76, 0x02, 0x60, 0x28, 0xC8, 0x00, 0x00, 0x07, 0xF8, 0x00,
0x00, 0x60, 0x04, 0x00, 0x0E, 0x20, 0x00, 0x00, 0x00, 0x27, 0x30, 0x00, 0x00, 0x00, 0xFF, 0x00,
0x03, 0x80, 0x00, 0x00, 0x19, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xC0,
0x04, 0x00, 0x01, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xF8,
0x18, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0,
0x00, 0x10, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
0x00, 0x28, 0x01, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x11, 0x80, 0x00, 0x00, 0x00, 0x04, 0x02, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x03, 0x8C, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x01, 0xD8, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0xA0, 0x00, 0x00, 0x00, 0x00, 0x70, 0x18, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x20, 0x0F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
 
void draw(void) {
  // graphic commands to redraw the complete screen should be placed here  
  u8g.drawBitmapP( 0, 0,16,36, rook_bitmap);
}
 
void setup(void) {
 
}
 
void loop(void) {
  // picture loop
  u8g.firstPage();  
  do {
    draw();
    u8g.drawLine(64,60,counter, 10);
 
  } while( u8g.nextPage() );
 
  // rebuild the picture after some delay
  //delay(1000);
      counter++;
    if (counter==128) counter=0;
 
}


This last code starts with the line in the center and moves left or right depending on the push-buttons:
#include "U8glib.h"
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NO_ACK);  // Display which does not send ACK
 
//defining hardware resources.
#define LED 13
#define FOOTSWITCH 12
#define TOGGLE 2
#define PUSHBUTTON_1 A5
#define PUSHBUTTON_2 A4

//defining the output PWM parameters
#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz
#define PWM_MODE 0 // Fast (1) or Phase Correct (0)
#define PWM_QTY 2 // 2 PWMs in parallel

const uint8_t rook_bitmap[] U8G_PROGMEM = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x03, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xE0, 0x12, 0x04, 0x80, 0x10, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x19, 0xC0, 0x20, 0x0C, 0x03, 0x80, 0x10, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0A, 0x20, 0x40, 0x12, 0x00, 0x80, 0x10, 0x48, 0x00, 0x70, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0A, 0x20, 0x40, 0x0C, 0x03, 0x00, 0x10, 0x30, 0x00, 0x08, 0x00, 0x00, 0x00,
0x00, 0x1C, 0x30, 0x0A, 0x20, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x00, 0x02, 0x48, 0x09, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0xF0, 0x00,
0x00, 0x0E, 0x48, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x20, 0x20, 0x00, 0x70, 0x00, 0x80, 0x00,
0x00, 0x10, 0x48, 0x00, 0x00, 0x20, 0x04, 0x01, 0x08, 0x20, 0x20, 0x00, 0x00, 0x00, 0xE0, 0x00,
0x00, 0x1E, 0x30, 0x00, 0x20, 0x20, 0x04, 0x01, 0x08, 0x40, 0x44, 0x00, 0x00, 0x00, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x04, 0x01, 0x08, 0x40, 0x44, 0x20, 0x40, 0x00, 0xE0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x04, 0x01, 0x08, 0x40, 0x48, 0x20, 0x40, 0x00, 0x00, 0x10,
0x00, 0x00, 0x10, 0x40, 0x10, 0x10, 0x1F, 0xFF, 0xFF, 0xE0, 0xF8, 0x40, 0x40, 0x00, 0x00, 0x10,
0x00, 0x00, 0x18, 0x20, 0x08, 0x1F, 0xE0, 0x00, 0x00, 0x1F, 0xFF, 0xC0, 0x84, 0x03, 0x00, 0x10,
0x7F, 0x80, 0x0C, 0x20, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFC, 0x84, 0x04, 0x00, 0xFE,
0x00, 0x00, 0x04, 0x11, 0xF0, 0x00, 0x08, 0x00, 0x80, 0x00, 0x1F, 0xFF, 0xE8, 0x04, 0x00, 0x10,
0x00, 0x00, 0x66, 0x1E, 0x00, 0x00, 0x08, 0x00, 0x80, 0x03, 0x00, 0x3F, 0xFC, 0x08, 0x00, 0x10,
0x00, 0x01, 0xE3, 0xE0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0xFF, 0xD0, 0x00, 0x10,
0x00, 0x01, 0xFE, 0x00, 0x02, 0x00, 0x76, 0x07, 0x60, 0x00, 0x00, 0x00, 0x1F, 0xF8, 0x00, 0x00,
0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x69, 0x81, 0x90, 0x67, 0x30, 0x00, 0x03, 0xFF, 0x00, 0x00,
0x00, 0x03, 0x80, 0x00, 0x19, 0xC0, 0x19, 0x82, 0x90, 0x28, 0xC8, 0x00, 0x00, 0x3F, 0xE0, 0x00,
0x00, 0x1C, 0x08, 0x00, 0x06, 0x20, 0x76, 0x02, 0x60, 0x28, 0xC8, 0x00, 0x00, 0x07, 0xF8, 0x00,
0x00, 0x60, 0x04, 0x00, 0x0E, 0x20, 0x00, 0x00, 0x00, 0x27, 0x30, 0x00, 0x00, 0x00, 0xFF, 0x00,
0x03, 0x80, 0x00, 0x00, 0x19, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xC0,
0x04, 0x00, 0x01, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xF8,
0x18, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0,
0x00, 0x10, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
0x00, 0x28, 0x01, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x11, 0x80, 0x00, 0x00, 0x00, 0x04, 0x02, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x03, 0x8C, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x01, 0xD8, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0xA0, 0x00, 0x00, 0x00, 0x00, 0x70, 0x18, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x20, 0x0F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
 
//other variables
int input, bit_crush_variable=0;
int counter=0;
int count=64; //initially in mid position
 
void setup() {
  //setup IO
  pinMode(FOOTSWITCH, INPUT_PULLUP);
  pinMode(TOGGLE, INPUT_PULLUP); 
  pinMode(PUSHBUTTON_1, INPUT_PULLUP);
  pinMode(PUSHBUTTON_2, INPUT_PULLUP);
  pinMode(LED, OUTPUT);
  pinMode(6, OUTPUT); //PWM0 as output
  pinMode(7, OUTPUT); //PWM1 as output
 
  // setup PWM
  TCCR4A = (((PWM_QTY - 1) << 5) | 0x80 | (PWM_MODE << 1)); //
  TCCR4B = ((PWM_MODE << 3) | 0x11); // ck/1
  TIMSK4 = 0x20; // interrupt on capture interrupt
  ICR4H = (PWM_FREQ >> 8);
  ICR4L = (PWM_FREQ & 0xff);
  DDRB |= ((PWM_QTY << 1) | 0x02); // turn on outputs
  sei(); // turn on interrupts - not really necessary with arduino
  }
 
void loop() 
{
 
  {  
    digitalWrite(LED, LOW); // switch-off the LED
    u8g.firstPage(); 
    do {
      //  u8g.setFont(u8g_font_helvR24r);
      //  u8g.drawStr( 0, 30, "EFFECT");    
      //  u8g.drawStr( 0, 60, "  OFF ");   
      u8g.drawBitmapP( 0, 0,16,36, rook_bitmap);
      u8g.drawLine(64,60,count, 10);
 
        } while( u8g.nextPage() );
  }
}
 
ISR(TIMER4_CAPT_vect) 
{
counter++; //to save resources, the pushbuttons are checked every 10000 times.
if(counter==1000)
{ 
counter=0;
if (!digitalRead(PUSHBUTTON_1)) 
    {
     if (count<126)count--;
     digitalWrite(LED, HIGH); //blinks the led
    }
 
    if (!digitalRead(PUSHBUTTON_2)) 
    {
      if (count>2)count++;
      digitalWrite(LED, HIGH); //blinks the led
    }
}
}
Last Edit: 8 months 3 weeks ago by ElectroSmash_Team.
The administrator has disabled public write access.
Time to create page: 0.275 seconds
Powered by Kunena Forum
Joomla SEF URLs by Artio

Our Instagram

Follow us

You can also follow us on:

facebook   google   instagram

pinterest   youtube   twitter