hapit
Published © MIT

MSAMS example + library for Arduino UNO (ver.3) and I2C OLED

MSAMS (Microcontroller Software Application Modular Synthesizer) library + an example for direct upload to UNO.

IntermediateShowcase (no instructions)118
MSAMS example + library for Arduino UNO (ver.3) and I2C OLED

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Rotary Potentiometer, 10 kohm
Rotary Potentiometer, 10 kohm
×2
Pushbutton Switch, Push-Pull
Pushbutton Switch, Push-Pull
×1
USB-A to B Cable
USB-A to B Cable
×1
Graphic OLED, 128 x 64
Graphic OLED, 128 x 64
×1

Story

Read more

Custom parts and enclosures

MSAMS_Controller_gerber

Schematics

MSAMS_Controller_diagram

Code

MSAMS example

Arduino
Before any code is uploaded to the board, make sure MSAMSComponents and OLED_SSD1306__SSD1106-1.0.7 libraries are included into the IDE's default library path.

How to use:
1. Normally open the MSAMS.ino file in your Arduino IDE in your PC or Mac
2. Check for possible errors (press the Compile Sketch Button in your IDE)
3. If all right, press Upload button to upload the code to Arduino
#include <MSAMSComponents.h>
#include <oled.h>

/*
*  DISCLAIMER
*  When MSAMSComponents library is included
*  we have to define one pointer for each
*  LED, Button or Potentiometer of their
*  base class MSAMSComponent so that we are
*  able to configure each one (invoke void cfg()).
*  Example:
*  //create Button component
*  Button b(6);
*  
*  //create a base (MSAMSComponent) pointer
*  MSAMSComponent *bs = &b;
*  //in void setup(), configure b as:
*  bs->cfg();
*/

bool cleared = false;
Button b(6);
Potentiometer p1(A0);
Potentiometer p2(A1);
MSAMSComponent *bs = &b;
MSAMSComponent *p1c = &p1;
MSAMSComponent *p2c = &p2;
OLED display(
  18,
  19,
  NO_RESET_PIN,
  OLED::W_128,
  OLED::H_64,
  OLED::CTRL_SSD1306,
  0x3c
);

void setup() {
  Serial.begin(115200);
  bs->cfg();
  p1c->cfg();
  p2c->cfg();
  display.begin();
}

void charStr(int num, OLED &display_, int x = 0, int y = 0) {
  String sn = String(num);
  const int size_ = (sizeof sn / sizeof num) + 1;
  char getNum[size_];
  for(int i = 0; i <= size_; i++) {
    if(i == size_) getNum[i] = '\0';
    else getNum[i] = sn[i];
  }
  display_.draw_string(x, y, getNum);
}

void charLine(int num, OLED &display_, int x = 0, int y = 0) {
  int mn = map(num, 0, 1023, x, OLED::W_128);
  display_.draw_line(x, y, mn, y);
}

void loop() {
  int bs, p1s, p2s;
  String channelA = "", channelB = "", channelC = "";
  p1s = p1.getState();
  channelA = (String)p1s;
  channelA = 'a' + channelA;
  p2s = p2.getState();
  channelB = (String)p2s;
  channelB = 'b' + channelB;
  bs = b.getState();
  channelC = (String)bs;
  channelC = 'c' + channelC;
  if(bs == 1) {
    p2s = map(p2s, 0, 1023, 0, OLED::H_64 - 12);
    charLine(p1s, display, 0, p2s);
    charStr(p1s, display, 0, p2s + 4);
    display.display();
    display.clear();
    cleared = false;
  }
  else {
    if(!cleared) {
      display.clear();
      display.display();
      cleared = true;
    }
  }
  Serial.println(channelA);
  Serial.println(channelB);
  Serial.println(channelC);
  delay(30);
}

MSAMS Library

Credits

hapit
2 projects • 0 followers

Comments