Saturday, 10 April 2021

Master clock / divider & multiplier - Millis() - OLED display

My third attempt at using an Arduino to make a master clock with dividers and multipliers.
This is a good beginners circuit.
 
 
My earlier attempts are here:
You can of course just buy a clock multiplier / divider, but where's the fun in that.
 
i'M USING  a basic Arduino Uno
The OLED communicates via i2c
PinWiring to Arduino Uno
Vin5V
GNDGND
SCLA5
SDAA4
 

 
The POT is wired thus:
centre (wiper) to A0
Right to GND
Left to 5V
 
The pot supplies an analog voltage which is converted into a digital
signal by the Arduino's ADCs.
Maybe an encoder would be better used??
 

 
 
The 4 LEDs
Cathode to gnd via 220 ohm resistors
Anode to pins 8, 9, 10, 11. 

I played around with the delay function, but the Millis function works much better.
 
I'm not a coder so if you can suggest any improvements, let me know.
Feel free to hack & improve the code.


The code:
 
 // &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

/*
This is part of a project to build a Synth master clock module with multipliers and dividers
Hopefully will add MIDI later.
jondent808@gmail.com 
https://djjondent.blogspot.com/2018/03/arduino-index.html
 
*/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

const int ledPin =  8;// the number of the LED pin 8
int ledState = LOW;             // ledState used to set the LED 8
const int ledPin9 =  9;// the number of the LED pin 9
int ledState9 = LOW;             // ledState used to set the LED 9
const int ledPin10 =  10;// the number of the LED pin 10
int ledState10 = LOW;             // ledState used to set the LED 10
const int ledPin11 =  11;// the number of the LED pin 11
int ledState11 = LOW;             // ledState used to set the LED 11

#define MIN_BPM 20      /*write here the min BPM that you want */
 #define MAX_BPM 300     /* write here the max BPM that you want */
 #define POT A0          // the potentiometer connects to analog pin A0

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

// Variables
int bpm;

unsigned long previousMillis = 0;        // will store last time LED was updated
unsigned long previousMillis9 = 0;        // will store last time LED9 was updated
unsigned long previousMillis10 = 0;        // will store last time LED10 was updated
unsigned long previousMillis11 = 0;        // will store last time LED11 was updated
 
const long interval = 60000;           // interval at which to blink (milliseconds)
const long interval2 = 30000;           // interval * 2
const long interval4 = 15000;           // interval * 4
const long interval8 = 7500;           // interval * 8

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin9, OUTPUT);
  pinMode(ledPin10, OUTPUT);
  pinMode(ledPin11, OUTPUT);
  digitalWrite(ledPin,ledState);// set initial state of pin 8 LED
  digitalWrite(ledPin9,ledState9);// set initial state of pin 9 LED
  digitalWrite(ledPin10,ledState10);// set initial state of pin 10 LED
  digitalWrite(ledPin11,ledState11);// set initial state of pin 11 LED
 
 
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C
  display.clearDisplay(); // Clear the buffer.
}

void loop() {

   bpm = map(analogRead(POT), 0, 1023, MIN_BPM, MAX_BPM);  
    display.clearDisplay();
    display.setTextSize(3);
    display.setTextColor(WHITE);
    display.setCursor(0,0);
    display.println(bpm);
    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.println("    BPM");
    display.display();
    
 
unsigned long currentMillis = millis();
unsigned long currentMillis9 = millis();
unsigned long currentMillis10 = millis();
unsigned long currentMillis11 = millis();

  if (currentMillis - previousMillis >= interval/bpm) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED 8 is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }
 // set the LED 8 with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }

    // **********************************
    
 if (currentMillis9 - previousMillis9 >= interval2/bpm) {
    // save the last time you blinked the LED
    previousMillis9 = currentMillis9;
    
    // if the LED 9 is off turn it on and vice-versa:
    if (ledState9 == LOW) {
      ledState9 = HIGH;
    } else {
      ledState9 = LOW;
    }
    // set the LED 9 with the ledState of the variable:
    digitalWrite(ledPin9, ledState9);
  }
  // ********************************************
      
 if (currentMillis10 - previousMillis10 >= interval4/bpm) {
    // save the last time you blinked the LED
    previousMillis10 = currentMillis10;
    
    // if the LED 10 is off turn it on and vice-versa:
    if (ledState10 == LOW) {
      ledState10 = HIGH;
    } else {
      ledState10 = LOW;
    }
    // set the LED 10 with the ledState of the variable:
    digitalWrite(ledPin10, ledState10);
  }
  //*******************************************

  if (currentMillis11 - previousMillis11 >= interval8/bpm) {
    // save the last time you blinked the LED
    previousMillis11 = currentMillis11;
    
    // if the LED 11 is off turn it on and vice-versa:
    if (ledState11 == LOW) {
      ledState11 = HIGH;
    } else {
      ledState11 = LOW;
    }
    // set the LED 11 with the ledState of the variable:
    digitalWrite(ledPin11, ledState11);
}
}

// &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 



 ---------------------------------
-------------------------------------

coco cavoodle

 2

Wednesday, 7 April 2021

Vitalise - Upcoming synth meet & performances

 
 

  This is a nine week run of  live electronic music.
Held Thursday evenings, between 6pm and midnight.
 
Good Space 
33 Playfair St,
&
106-108 George St, The Rocks
 
Sydney
NSW AUSTRALIA


Facebook
 


 

Week 6

OLED - Displaying real time info

OLEDs are pretty cool .
This is the standard Adafruit splash screen.
I think it demonstrates well the capabilities of these little windows.
I'm sure you've seen OLEDs in plenty of synths.
 

To get a better understanding of this technology, I've started mucking around with Arduinos, and  various displays. LCDs are OK, but OLEDS are the bomb.



 
The Buchla logo is just lovely on this screen.


Up till now, all the images and text is part of the code.
In order to change the display, you need to change the code itself.
 
Thus this post.
It's actually a combination of two posts.
 
 The first post covered how to read & display the voltage on 
the output of an Arduino on a serial monitor.
The serial monitor is part of Arduino's IDE and communicates real time info.



The second post covered how to display info on a OLED screen.
 

So why not combine the two.
Though this may seem pretty basic, I think it's a important building block.
 
This is the code of how to read & display Arduino voltages on a OLED & the Serial monitor.
 
 

 
So so simple.
 
Feel free to copy, paste & hack

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

// set up variables
int myVoltPin=A2;
int readVal;
float V2;
 int delayT=250;


void setup()
{
  Serial.begin(9600);
  // initialize with the I2C addr 0x3C
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  

   // Clear the buffer.
  display.clearDisplay();
 
}

void loop()
{
  readVal=analogRead(myVoltPin);
  V2=(5./1023.)*readVal;
  // converts to a voltage -- remember to place the decimal
  // points after the 5 & 1023 ... these may be floating points
  Serial.println(V2);

  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("Voltage");
  display.println(" ");
  display.setTextSize(3);
  display.println(V2);
 
  display.display();
  delay(delayT);
  display.clearDisplay();
}

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

-------------------------------------------------------------------------------------------

 ---------------------------------
-------------------------------------

Tuesday, 6 April 2021

Ender's Game - Orson Scott Card

The book originated as a short story of the same name, published in the August 1977 issue of Analog Science Fiction and Fact.
Just 34 pages long.

 The novel was published on January 15, 1985.  
Its 324 pages long.
 
Ender's Game was recognized as "best novel" by the 1985 Nebula Award[3] and the 1986 Hugo Award[4

Its four sequels—Speaker for the Dead (1986), Xenocide (1991), Children of the Mind (1996), and Ender in Exile (2008)follow Ender's subsequent travels to many different worlds in the galaxy. In addition, the later novella A War of Gifts (2007) and novel Ender's Shadow (1999), plus other novels in the Shadow saga, take place during the same time period as the original

 

 



In order to develop a secure defense against a hostile alien race's next attack, government agencies breed child geniuses and train them as soldiers.  















--------------------------------------------

sci Fi Index

----------------------------------------------

Saturday, 3 April 2021

Friday, 2 April 2021

LCD Timer - i2c - Arduino

This is a nice simple timer circuit using an Arduino Uno, a LCD, two buttons, 
two LEDS and some resistors.
 

It's a stopwatch (and not directly synth related) , but the basic code is great for working out how an arduino clock works and how to display that info on a LCD.
Here is the instructables link:
 
 

 
I've changed the code a little to work with my LCD
And varied the resistors.
The switches are connected to gnd with 330 ohm resistors
The LEDs anodes connect to pins 2 & 3 via 220 ohm resistors.
Cathodes then connect straight to gnd.

Image made using Tinkercad

 

Many thanks to Jay 625549

The code is here:
//********************************
//Jay Raut Jean Augustine Secondary
//January 13 2020
//625549@pdsb.net
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup()
{
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
lcd.backlight();//turns on backlight
pinMode(8, INPUT);//setting up Pins on arduino for output and input from leds and buttons
digitalWrite(8, HIGH);
pinMode(9, INPUT);
digitalWrite(9, HIGH);
pinMode(2, OUTPUT);
digitalWrite(2, LOW);
pinMode(3, OUTPUT);
digitalWrite(3, LOW);

}
double i = 0;//variables for recording time
double a = millis();
double c ;
void loop()
{
lcd.clear();
lcd.print("press the button");

 if(digitalRead(8) == LOW)//clears LCD when button is pressed
 {
    lcd.clear();
    a = millis();

   while(digitalRead(9) == HIGH)
   {
   c = millis();//function to start recording when the button was pressed to print on the LCD
   i = (c - a) / 1000;
   lcd.print(i);
   lcd.setCursor(7,0);
   lcd.print("Seconds");
   lcd.setCursor(0,0);
   digitalWrite(2, HIGH);//turns on green led
   digitalWrite(3, LOW);//turns off red led
   }
   if(digitalRead(9) == LOW)
   {
     while(digitalRead(8) == HIGH)//if other button is pressed then clear the LCD
     {
       lcd.setCursor(0,0);

       lcd.setCursor(11,0);
       lcd.print("");
       lcd.setCursor(0,0);
          digitalWrite(2, LOW);//turn off the green led
          digitalWrite(3, HIGH);//turn on the red led
     }
   }
 }
}

// *****************************
 

Links
+ Momentary push buttons & Pull down resistors  

 ---------------------------------
-------------------------------------