/**************************************************************************
/**************************************************************************
This is an example for our Monochrome OLEDs based on SSD1306 drivers
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/category/63_98
This example is for a 128x64 pixel display using I2C to communicate
3 pins are required to interface (two I2C and one reset).
Adafruit invests time and resources providing this open
source code, please support Adafruit and open-source
hardware by purchasing products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries,
with contributions from the open source community.
BSD license, check license.txt for more information
All text above, and the splash screen below must be
included in any redistribution.
**************************************************************************/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Button.h>
#include <EncoderButton.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
static const unsigned char PROGMEM logo_bmp[] =
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf7, 0x00, 0x00, 0x03, 0xc3, 0xc0, 0x00,
0x07, 0x80, 0xf0, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x08, 0x36, 0x08, 0x00, 0x10, 0xf7, 0x84, 0x00,
0x11, 0xf7, 0x84, 0x00, 0x31, 0xf7, 0xce, 0x00, 0x33, 0xff, 0xc6, 0x00, 0x33, 0xff, 0xe6, 0x00,
0x23, 0xff, 0xe2, 0x00, 0x23, 0xff, 0xc2, 0x00, 0x21, 0xff, 0xc2, 0x00, 0x21, 0xff, 0xc4, 0x00,
0x18, 0xff, 0x8c, 0x00, 0x1c, 0x7f, 0x18, 0x00, 0x0c, 0x00, 0x38, 0x00, 0x06, 0x00, 0x30, 0x00,
0x02, 0x00, 0x60, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00};
static const unsigned char PROGMEM button_bmp[] =
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x18, 0x00, 0x1e, 0x68, 0x00, 0x39, 0x9c, 0x00, 0x37,
0xec, 0x00, 0x6f, 0xf6, 0x00, 0xef, 0xf6, 0x00, 0xff, 0xf7, 0x00, 0xef, 0xf7, 0x00, 0x6f, 0xf6,
0x00, 0x6f, 0xf6, 0x00, 0x37, 0xec, 0x00, 0x38, 0x1c, 0x00, 0x1f, 0xf8, 0x00, 0x0f, 0xf0, 0x00,
0x00, 0x00, 0x00};
static const unsigned char PROGMEM sin_bmp[] =
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x70, 0x10, 0x88, 0x11, 0x08, 0x0f, 0x08, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00};
static const unsigned char PROGMEM saw_bmp[] =
{ 0x00, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x03, 0x1c, 0x05, 0x3c, 0x19, 0x44, 0x31, 0x8c, 0x20, 0x00,
0x00, 0x00, 0x00, 0x00};
static const unsigned char PROGMEM tri_bmp[] =
{ 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x03, 0xc0, 0x0c, 0x60, 0x18, 0x30, 0x30, 0x1c, 0x60, 0x04,
0x00, 0x00, 0x00, 0x00};
static const unsigned char PROGMEM sqr_bmp[] =
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x10, 0x42, 0x10, 0x42, 0x10, 0x42, 0x10, 0x03, 0xf0,
0x00, 0x00, 0x00, 0x00};
static const unsigned char PROGMEM tune_bmp[] =
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x10, 0xc6, 0x30, 0x86, 0x10, 0x86, 0x1f, 0x86,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char PROGMEM oscil_bmp[] =
{ 0xff, 0xff, 0xff,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, 0x35, 0xaa, 0xdf, 0xe0, 0xfb, 0x35, 0xaa, 0xdf, 0xe0, 0xf8, 0xc4,
0x62, 0x47, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff,
0xff, 0xe0, 0xff, 0xef, 0x23, 0xff, 0xe0, 0xff, 0xea, 0xdd, 0xff, 0xe0, 0xff, 0xea, 0xdd, 0xff,
0xe0, 0xff, 0xf6, 0x23, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xe0,
0xff, 0xff, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xe0};
int sensorPin1 = A1;
int sensorPin2 = A2;
int boutonPin1 = 4;
int boutonPin2 = 7;
int sensorValue1 = 0;
int sensorValue2 = 0;
int boutonValue2 = 0;
int lastsensorValue = 0;
String titre = "2 VCO";
Button button1(12); // Connect your button between pin 2 and GND
int selection1=0;
Button button2(7); // Connect your button between pin 2 and GND
int selection2=0;
Button button3(8); // Connect your button between pin 2 and GND
int mode=0;
float pos2 = 0;
EncoderButton eb1(2, 3, 5);
void onEb1Encoder(EncoderButton& eb) {
//display.print("eb1 incremented by: ");
//display.println(eb.increment());
//Serial.print("eb1 position is: ");
//Serial.println(eb.position());
display.setCursor(107,50);
display.setTextColor(BLACK, WHITE);
display.setCursor(107,50);
display.println();
display.setCursor(107,50);
float pos1=eb.position();
if (eb.position()<0){
pos1=0;
}
display.println(pos1,1);//define analog pin
//draw triangle
if (pos1 <= 7) {
//display.fillTriangle(5 + pos1 * 7, 28, 2 + pos1 * 7, 33, 8 + pos1 * 7, 33, WHITE);
//display.fillTriangle(5 + (pos1+1) * 7, 28, 2 + (pos1+1) * 7, 33, 8 + (pos1+1) * 7, 33, BLACK);
//display.fillTriangle(5 + (pos1-1) * 7, 28, 2 + (pos1-1) * 7, 33, 8 + (pos1-1) * 7, 33, BLACK);
display.fillCircle(4+15*pos1, 28, 3, WHITE);
display.fillCircle(4+15*(pos1-1), 28, 3, BLACK);
display.fillCircle(4+15*(pos1+1), 28, 3, BLACK);
}
}
void onEb1Clicked(EncoderButton& eb) {
//float pos2 = eb.clickCount();
if (eb.clickCount()){
//Serial.println("Button 1 pressed");
pos2+=1;
}
if (pos2 > 1)
pos2 = 0;
display.setCursor(107,40);
display.setTextColor(BLACK, WHITE);
display.setCursor(107,40);
display.println();
display.setCursor(107,40);
//float pos2 = eb.clickCount();
display.println(pos2,1);//define analog pin
//display.print("eb1 clickCount: ");
//display.println(eb.clickCount());
}
void setup() {
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.display();
delay(500); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
// Draw a single pixel in white
display.drawPixel(10, 10, SSD1306_WHITE);
// Show the display buffer on the screen. You MUST call display() after
// drawing commands to make them visible on screen!
display.display();
delay(500);
// display.display() is NOT necessary after every single drawing command,
// unless that's what you want...rather, you can batch up a bunch of
// drawing operations and then update the screen all at once by calling
// display.display(). These examples demonstrate both approaches...
testscrolltext(); // Draw scrolling text
// Invert and restore display, pausing in-between
//display.invertDisplay(true);
//delay(1000);
//display.invertDisplay(false);
//delay(1000);
button1.begin();
button2.begin();
button3.begin();
eb1.setClickHandler(onEb1Clicked);
eb1.setEncoderHandler(onEb1Encoder);
}
void loop() {
if (button1.pressed()){
//Serial.println("Button 1 pressed");
selection1+=1;
}
if (selection1 > 3)
selection1 = 0;
if (button2.pressed()){
//Serial.println("Button 1 pressed");
selection2+=1;
}
if (selection2 > 3)
selection2 = 0;
if (button3.pressed()){
//Serial.println("Button 1 pressed");
mode+=1;
}
if (mode > 4)
mode = 0;
potard(); // Draw scrolling text
//testscrolltext();
eb1.update();
}
void testscrolltext(void) {
display.clearDisplay();
display.setTextSize(1); // Draw 2X-scale text
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
//display.println(F("scroll"));
//display.println("scroll");
//display.setCursor(5, 3); //
//display.println("O1");
//display.setCursor(10, 50); //
//display.println("Wav1");
//display.setCursor(20, 340); //
display.drawCircle(9, 53, 5, SSD1306_WHITE);
display.drawCircle(54, 53, 5, SSD1306_WHITE);
display.drawCircle(99, 53, 5, SSD1306_WHITE);
//display.drawCircle(20, 20, 10, SSD1306_WHITE);
display.drawBitmap(9, 12, logo_bmp, 25, 25, SSD1306_WHITE);
display.drawBitmap(53, 12, logo_bmp, 25, 25, SSD1306_WHITE);
display.setCursor(10, 37); //
display.println("tun1");
display.setCursor(54, 37); //
display.println("tun2");
//display.drawBitmap(10, 35, button_bmp, 17, 17, SSD1306_WHITE);
//display.drawBitmap(50, 35, button_bmp, 17, 17, SSD1306_WHITE);
//display.setCursor(8, 55); //
//display.println("Wav1");
//display.setCursor(48, 555); //
//display.println("Wav2");
//display.drawBitmap(15, 48, sin_bmp, 15, 15, BLACK, WHITE);
//display.drawBitmap(64, 50, sin_bmp, 15, 10, BLACK, WHITE);
display.drawBitmap(92, 1, oscil_bmp, 32, 20, WHITE);
//display.drawBitmap(2, 20, tune_bmp, 10, 20, SSD1306_WHITE);
display.setTextSize(1);
display.setTextColor(BLACK, WHITE);
display.setCursor(93, 23); //
display.println("2 VCO");
display.display(); // Show initial text
delay(100);
}
void potard(void) {
//display.clearDisplay();
display.setTextSize(1); // Draw 2X-scale text
display.setTextColor(SSD1306_WHITE);
int sensorValue1 = analogRead(sensorPin1);
int sensorValue2 = analogRead(sensorPin2);
//map(sensorValue, 0, 1023, 30, 2000);
delay(1);//delay time 1 mili second display.clearDisplay();
//display.setTextSize(1);//text size
//display.setTextColor(WHITE);//text color
// display.setCursor(6,3);
//display.setTextColor(BLACK, WHITE);
//display.setCursor(6,3);
//display.println();
//display.setCursor(6,3);
//map(sensorValue1, 0, 1024, 0, 64);
int pot1 = sensorValue1/32;
//display.println(pot1,1);//define analog pin
display.fillRect(3+pot1,4,4,6, WHITE);
//display.fillRect(3+pot1-1,4,3,6, BLACK);
display.fillRect(3+pot1+5,4,6,6, BLACK);
//display.setTextColor(WHITE);//text color
display.setCursor(51,3);
display.setTextColor(BLACK, WHITE);
display.setCursor(51,3);
display.println();
display.setCursor(51,3);
float pot2 = sensorValue2/2;
display.println(pot2,1);//define analog pin
display.setCursor(95, 40); //
display.setTextColor(BLACK, WHITE);
display.setCursor(95, 40); //
display.println();
display.setCursor(95, 38); //
display.println(selection1);
display.drawRect(0, 0, 42, 63, WHITE);
display.drawRect(45, 0, 42, 63, WHITE);
display.drawRect(90, 35, 35, 28, WHITE);
switch (selection1) {
case 0:
display.drawBitmap(21, 49, sin_bmp, 15, 10, BLACK, WHITE);
break;
case 1:
display.drawBitmap(21, 49, saw_bmp, 15, 10, BLACK, WHITE);
break;
case 2:
display.drawBitmap(21, 49, tri_bmp, 15, 10, BLACK, WHITE);
break;
case 3:
display.drawBitmap(21, 49, sqr_bmp, 15, 10, BLACK, WHITE);
break;
}
switch (selection2) {
case 0:
display.drawBitmap(64, 49, sin_bmp, 15, 10, BLACK, WHITE);
break;
case 1:
display.drawBitmap(64, 49, saw_bmp, 15, 10, BLACK, WHITE);
break;
case 2:
display.drawBitmap(64, 49, tri_bmp, 15, 10, BLACK, WHITE);
break;
case 3:
display.drawBitmap(64, 49, sqr_bmp, 15, 10, BLACK, WHITE);
break;
}
switch (mode) {
case 0:
titre = " 2VCO ";
break;
case 1:
titre = " PWM ";
break;
case 2:
titre = "WShapr";
break;
case 3:
titre = " LFO ";
break;
case 4:
titre = " WoW ";
break;
}
display.setTextSize(1);
display.setCursor(90, 23); //
display.setTextColor(BLACK, WHITE);
display.setCursor(90, 23); //
display.println();
display.setCursor(90, 23); //
display.println(titre);
display.display(); // Show initial text
delay(1);
}