Thursday 29 March 2018

Switch Case Statements - Arduino

 This is a bit like a roundabout.
It's a control structure.
It lets you choose from many different routes.... depending of the value of a variable.
It's like a series of  "if" statements.

Good for menus... keeps everything tidy.
 
It starts with the word switch(). 
Then in the parenthesis, you type the name of the variable that determines the case

The break keyword exits the switch statement, and is typically used at the end of each case. 
 

 

Example 1
Many thanks to Programming Electronics for the example.
 
The circuit:
 * 5 LEDs attached to digital pins 2 through 6 through 220-ohm resistors

 created 1 Jul 2009
 by Tom Igoe

This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/SwitchCase2
 

 //************************************************************
/*
  Switch statement  with serial input

 Demonstrates the use of a switch statement.  The switch
 statement allows you to choose from among a set of discrete values
 of a variable.  It's like a series of if statements.

 To see this sketch in action, open the Serial monitor and send any character.
 The characters a, b, c, d, and e, will turn on LEDs.  Any other character will turn
 the LEDs off.

 The circuit:
 * 5 LEDs attached to digital pins 2 through 6 through 220-ohm resistors

 created 1 Jul 2009
 by Tom Igoe

This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/SwitchCase2
 */

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  // initialize the LED pins:
  for (int thisPin = 2; thisPin < 7; thisPin++) {
    pinMode(thisPin, OUTPUT);
  }
}

void loop() {
  // read the sensor:
  if (Serial.available() > 0) {
    int inByte = Serial.read();
    // do something different depending on the character received.
    // The switch statement expects single number values for each case;
    // in this exmaple, though, you're using single quotes to tell
    // the controller to get the ASCII value for the character.  For
    // example 'a' = 97, 'b' = 98, and so forth:

    switch (inByte) {
      case 'a':
        digitalWrite(2, HIGH);
        break;
      case 'b':
        digitalWrite(3, HIGH);
        break;
      case 'c':
        digitalWrite(4, HIGH);
        break;
      case 'd':
        digitalWrite(5, HIGH);
        break;
      case 'e':
        digitalWrite(6, HIGH);
        break;
      default:
        // turn all the LEDs off:
        for (int thisPin = 2; thisPin < 7; thisPin++) {
          digitalWrite(thisPin, LOW);
        }
    }
  }
}
//***********************************************************************
 

 
 
 
 Links
+ https://www.arduino.cc/reference/tr/language/structure/control-structure/switchcase/ 
+ https://www.programmingelectronics.com/tutorial-14-5-switch-case-statement-old-version/

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

Tuesday 27 March 2018

Rotary Encoder & switch/button press - arduino

I was looking for some code that utilised the encoder's switch.
The switch goes LOW when its pressed.
 
This is a very simple test of your encoder.
We Need to use the serial monitor to test.

It has 5 pins:
1. CLK - Clock (Out B)
2. DT - data (Out A)
3. SW - switch (when we press the shaft, the switch connects to GND. Otherwise it is floating.)
4. + : Vcc
5. GND
 

You most often will find encoders without the breakout board.
 
They still have 5 pins.
Here there are two GNDs
There is no Vcc
 
 
 
 
 
 
Make sure you connect both ground pins.
Connect the CLK (out B) to digital pin#2
DT (out A)  to #3 
SW (switch) to digital pin 4
 


 
 This is the code.
// *****************************
// Rotary Encoder Inputs
// the declaration of the Arduino pins to which the encoder’s CLK, DT 
// and SW pins are connected. 
#define CLK 2
#define DT 3
#define SW 4

int counter = 0; //  represents the count that will be modified each time that the knob is rotated one detent (click).
int currentStateCLK; // hold the state of the CLK output and are used for determining the amount of rotation.
int lastStateCLK;
String currentDir =""; //used when printing the current direction of rotation on the serial monitor.
unsigned long lastButtonPress = 0;//  used to debounce a switch

void setup() {
	
	// Set encoder pins as inputs
	pinMode(CLK,INPUT);
	pinMode(DT,INPUT);
	pinMode(SW, INPUT_PULLUP);

	// Setup Serial Monitor
	Serial.begin(9600);

	// Read the initial state of CLK and store it in the lastStateCLK variable
	lastStateCLK = digitalRead(CLK);
}

void loop() {
	
	// Read the current state of CLK
	currentStateCLK = digitalRead(CLK);

	// If last and current state of CLK are different, then pulse occurred
	// React to only 1 state change to avoid double count
	if (currentStateCLK != lastStateCLK  && currentStateCLK == 1){

		// If the DT state is different than the CLK state then
		// the encoder is rotating CCW so decrement
		if (digitalRead(DT) != currentStateCLK) {
			counter --;
			currentDir ="CCW";
		} else {
			// Encoder is rotating CW so increment
			counter ++;
			currentDir ="CW";
		}

		Serial.print("Direction: ");
		Serial.print(currentDir);
		Serial.print(" | Counter: ");
		Serial.println(counter);
	}

	// Remember last CLK state
	lastStateCLK = currentStateCLK;

	// Read the button state
	int btnState = digitalRead(SW);

	//If we detect LOW signal, button is pressed
	if (btnState == LOW) {
		//if 50ms have passed since last LOW pulse, it means that the
		//button has been pressed, released and pressed again
		if (millis() - lastButtonPress > 50) {
			Serial.println("Button pressed!");
		}

		// Remember last button press event
		lastButtonPress = millis();
	}

	// Put in a slight delay to help debounce the reading
	delay(1);
}
//**************************************************


 
 Links
 Last minute engineers provided the code in this post. Many thanks.
 
+ https://www.instructables.com/Improved-Arduino-Rotary-Encoder-Reading/ 
+ https://playground.arduino.cc/Main/RotaryEncoders/
 
 ---------------------------------
-------------------------------------

Tuesday 20 March 2018

Korg Electribe - History

 The Korg Electribe is a classic series of electronic instruments the first
of which started production last century. The range is still being produced today.
They use both analog modeling & sampling technologies.
They started as synths, drum machines & samplers.
The modern Electribes are fully integrated workstations.
 

Up to today, there have been 4 generations.

--------------------------------------------------
1st generation - Released 1999-2001

 
    EA-1: Analog Modeling Synthesizer 

    1999. Purely a synth.
     Two voices, 1 filter
      Distortion, Tempo delay, chorus/flanger
      MIDI
 
 
 
 
 
 
 
 
 

 
 
  ER-1: Rhythm Synthesizer. 
     Drum Machine
      1999. 
      10 Parts (4 synthesizer parts,
                    2 audio in parts,   
                    2 hi-hat parts, 
                    1 crash cymbal part, 
                    1 hand clap part)
      MIDI
 
 
 
 
 
ES-1: Rhythm Production Sampler
Year 2000
This was one of the first samplers that let you process recorder sounds.
They were 32kHz.
This could store up to 95 seconds (mono) or 47.5 seconds (stereo) or recording time .
100 mono or 50 stereo samples can be stored.
 
MIDI
 12 parts
 EM-1: Music Production Station
Year : 2001
 This was the first music production station.
It combined a drum machine and two synth parts.
 
 The drum machine had 8 voices.

Lots of effects.
Eg Reverb, Flanger/Chorus, Phaser, Ring modulator, Pitch shifter, Compressor, Distortion, 
delays, etc.
 
 
 
--------------------------------------------
 

 2nd generation - Released 2003-4
Korg released Mark2 versions of their synth, drum and sampler electribes.

  

  EA-1 mkII: Analog Modeling Synthesizer
Again , purely a synth.
   
 number of parts: 2
Memory: 256 pieces patterns_16
 
 
 
 
 
 
 
 
 

 ER-1 mkII: Rhythm Synthesizer
The drum machine.
combines a four-part DSP-based synthesizer with four additional PCM sound sources,
  
 
 
 
 
 
 
 
 
 
 

ES-1 mkII: Rhythm Production Sampler 

    (using SmartMedia storage. Maximum size card recognized is 64MB)
 Number of parts: 12
 Maximum Sampling Time: 95 (mono) / 47.5 (stereo) seconds
 
 
 
 
 
 
 
 

  ESX-1: Music Production Sampler (using SmartMedia storage)
This is a workstation.
Interesting as they added vacuum tubes.
 16 voices
2 synth parts, 9 drum parts, 1 drum accent part, 2 stretch part, 1 slice part, 1 audio in part
 
 Sampling frequency: 44.1 kHz
Maximum 285 (mono) seconds
 
 
 
 
 
   
EMX-1: Music Production Station
2003
 (using SmartMedia storage)
 Again ... Tubes
16 voices.
  5 synth parts, 9 drum parts, 1 synthesizer accent part, 1 drum accent part
 
 4 types of filter. LP, BP, HP, BP+
 
 
 
 
 
 
 
 
-----------------------------------
 
3rd generation - Released 2010
These were identical to the ESX & EMX above, except they used SD cards instead of the Smart Media cards.

    ESX-1SD: Music Production Sampler
     (Identical to the ESX-1, but using Secure Digital (SD) storage)
    EMX-1SD: Music Production Station
     (Identical to the EMX-1, but using Secure Digital (SD) storage)
 
--------------------------
Apple iPad versions
 
  

  iElectribe: an app for the iPad
This is the GORILLAZ Edition

 
 
 
 
 
 
 
 
 
 
  

iElectribe: an app for the iPhone

 
 
 
 
 
 

 Electribe Wave: an app for the iPad and iPhone
 
 
 
 
 
 
 
 
 
 
 
 
 ---------------------

4th generation - Announced Sept 2014 
Still in production

   

electribe: Music Production Station
     (using SD Card storage)
 
 
 
 
 
 
 
 
 
 
 

   electribe sampler: Music Production Sampler
     (using SD Card storage)


8 LED shift register -arduino 74HC595

 A brief exercise using the 74HC595 Serial to Parallel Converter..
It's a shift register.
This chip has 8 outputs and 3 inputs.
The 74HC/HCT595 is a high-speed Si-gate CMOS device.
 
I remember building a Video synth module a few years ago that also used a shift register.
The Castle used a 4 bit module.... the CD4015
 
This 74HC595 is 8-bit. 
It's a 16 pin chip.
It's all digital  Designed to store 0's and 1's, not analog voltages.
So shouldn't be confused with synthesizer ASRs - analog shift registers (though the idea is the same).
 
Shift registers are basically  memory modules.
 
 
It's useful if you run out of pins on your Arduino.
The 74HC595 will help you make use of the pins you have .
You can even link multiple shift registers together to extend your output even more. 
 Most of the outputs pins are on the left. Inputs on the right. (fig 1)

Here is the data sheet.

The Data sheet describes it as a  8-stage serial shift register with a storage register and 3-state outputs. 
The shift register and storage register have separate clocks
What it does is take data from your Arduino ,& momentary store it, freeing up the pins for new data.
 
The inputs are:
MR (SRCLR) - pin 10 
SHcp - Shift Register clock - pin 11
STcp - Clock (RCLK) - pin 12 - storage register clock (LATCH)
OE - pin 13 - output enable 
Ds/SER - serial input (pin 14)

Both the shift register clock (SRCLK) and storage register clock (RCLK) are positive-edge triggered.
Pin 14 is your important DATA input pin
Pin 11 is the Clock
Pin 12 is the Latch
 
This is a good circuit diagram:

Q0 to Q7 & Q15, are the outputs
 
 
Connect ground & voltage (pins 8 & 16)

We are using digital pins 4, 5, 6.
The important connections are
  • Digital 4 from the arduino goes to pin #14 of the shift register (DATA)
  • Digital 5 from the arduino goes to pin #12 of the shift register (LATCH)
  • Digital 6 from the arduino goes to pin #11 of the shift register (CLOCK)

 The anodes of the LEDs connect via 270 ohm resistors to pins:15, 1, 2, 3, 4, 5, 6, 7.

On the LEDs, the cathode is connected to ground

Note:

Pin 13 is the output enable.
You could attach this to a PWM capable Arduino pin and use 'analogWrite' to control the brightness of the LEDs. At the moment, we need to attach it to ground. 
 
MR must also be connected to 5V

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



Code 1

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

 /*
    Adafruit Arduino - Lesson 4. 8 LEDs and a Shift Register
    */
     // declare your variables
     // these are the pins attached to the clock,latch &
     //data inputs
    int latchPin = 5;
    int clockPin = 6;
    int dataPin = 4;

    int delayTime = 500;

   /*  used to hold the pattern of which LEDs are currently
   turned on or off.
     Data of type 'byte' represents numbers using eight bits.
    */
    byte leds = 0;
     
    void setup()
    {
      pinMode(latchPin, OUTPUT);
      pinMode(dataPin, OUTPUT);  
      pinMode(clockPin, OUTPUT);
    }
     
    void loop()
    {
      leds = 0;
      updateShiftRegister();
      delay(delayTime);
      for (int i = 0; i < 8; i++)
      {
        bitSet(leds, i);
        updateShiftRegister();
        delay(delayTime);
      }
    }
     /*
     the actual data to be shifted into the shift register,
     which in this case is 'leds'.
     */
    void updateShiftRegister()
    {
       digitalWrite(latchPin, LOW);
       shiftOut(dataPin, clockPin, LSBFIRST, leds);
       digitalWrite(latchPin, HIGH);
    }

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

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


Monday 19 March 2018

Mutant Bassdrum - Hexinverter

Some picks of this great module i just finished building.

These aren't really build notes but I hope it will help others in their quest to build one of these.
Its not a difficult build at all.
All through hole components.

There are 2 PCBs. ... this is the lower.
The upper PCB holds the LEDs, pots etc.



Below are pics of the build process... working backwards.


 Be careful with the orientation of the vactrol.


Now I want to build all the drum modules. :-)

LINKS:
hEXINVERTER

-----------------------------------------------------------------------------------------------
For more Euro DIY builds click here:
http://djjondent.blogspot.com.au/2017/12/diy-index.html
------------------------------------------------------------------------------------------------- 

Sunday 18 March 2018

Arduino - Print Commands and the Serial Port

All Arduino boards have at least one serial port (also known as a UART or USART)
It communicates on digital pins 0 (RX) and 1 (TX) as well as with the computer via USB
 
You can use the Arduino environment’s built-in serial monitor to communicate with an Arduino board. Click the serial monitor button in the toolbar and select the same baud rate used in the call to begin().
Serial communication on pins TX/RX uses TTL logic levels (5V or 3.3V depending on the board).
 
The Print command allows us to read info from the Arduino.
   
The Syntax is
Serial.print ()

Serial.print("Hello world.") gives "Hello world."
Serial.print(78) gives "78"
 
This command prints data to the serial port as human-readable ASCII text.
 
An optional second parameter specifies the base (format) to use
ie
permitted values are BIN(binary, or base 2),  
Serial.print(78, BIN) gives "1001110"
 
OCT(octal, or base 8),  
Serial.print(78, OCT) gives "116"
 
DEC(decimal, or base 10),  
Serial.print(78, DEC) gives "78"
 
HEX(hexadecimal, or base 16).
Serial.print(78, HEX) gives "4E"
 
------------
code 1



------------------
// variables
int j=1;
int waitT=300; //delay

void setup()
{
Serial.begin (9600);
  //baud rate
    // this sets up the serial monitor
}

void loop()
{
 Serial.print(j);
  j=j+1;
    delay(waitT);
}
-----------------------------------------------------
code 2


This is really poor programming, as it's printing across the page.
 
the fix is easy
Add "ln"
 Serial.println(j); 















code 3

// variables
int j=1;
int waitT=300; //delay
String myString="j = ";

void setup()
{
Serial.begin (9600);
  //baud rate. Use higher baud rates to make it run faster.
    // this sets up the serial monitor
}

void loop()
{
 Serial.print(myString);
 Serial.println(j); // adding ln ... prints to a new line
  j=j+1;
    delay(waitT);
}

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

code 4

// variables
int j=1;
int waitT=300; //delay
int x=3;
int y=7;
int z;
String myString=" + ";

void setup()
{
Serial.begin (9600);
  //baud rate. Use higher baud rates to make it run faster.
    // this sets up the serial monitor
}

void loop()
{
  z=x+y;
  Serial.print(x);
  Serial.print(myString);
  Serial.print(y);
  Serial.print(" = "); // the quotes make it print =
  Serial.println(z);
}

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

Friday 16 March 2018

The Stars My Destination - Alfred Bester

 


Its first publication was in book form in June 1956 in the United Kingdom, where it was titled Tiger! Tiger!, named after William Blake's 1794 poem "The Tyger",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 It was serialized in Galaxy magazine in four parts beginning with the October 1956 issue
 

 
 

 This is the 1957 edition 
March 21, 1957
US version
Signet Books
Paperback













Wednesday 14 March 2018

Arduino Index

 Index for all things Arduino
 
+ Momentary push buttons & Pull down resistors
+ analogRead command  
 
 
 
 
 
 
+ Tone() function - adding noise  
+ Functions - general - creating new functions, etc
 
 
+ i2c LCD Timer - stopwatch 
 
 
+ millis() function - blinking 1 LED

Monday 12 March 2018

Modular on the Lounge - second meeting

A great night had by all.

Visuals were provided with a LZV Vidiot video synth

A post shared by jono (@dj_jondent) on
Sat 10th March.
Wollongong, Australia.

A post shared by jono (@dj_jondent) on
We will try to hold these events regularly ... every 2 to 3 months

Jerusalem - Mount of Olives Cemetery, Israel.

This is the most important cemetery in Jerusalem. It started during the first Temple period and It is still being used today.


The cemetery contains anywhere between 70,000 and 2 or 300,000 tombs

 During the First and Second Temple Periods the Jews of Jerusalem were buried in burial caves scattered on the slopes of the Mount, and from the 16th century the cemetery began to take its present shape.
(Wikipedia)

..: According to Jewish tradition, it is here that the Resurrection of the Dead would begin. The Messiah would appear on the Mount of Olives and head toward the Temple Mount.


 Ariel view

WikiAir IL-13-06 039 - Mount of Olives.JPG
By Neukoln, CC BY-SA 3.0, Link

For more travel postcards click here: