The Alpha Geek – Geeking Out

Arduino

Arduino

Project #21 – Nixie – Stopwatch – Mk04

——

#DonLucElectronics #DonLuc #NixieTube #Nixie #ArduiNIX #ArduinoMega2560 #Arduino #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant

——

Stopwatch

——

Stopwatch

——

Stopwatch

——

Stopwatch

A stopwatch is a timepiece designed to measure the amount of time that elapses between its activation and deactivation. In manual timing, the clock is started and stopped by a person pressing a button. The timing functions are traditionally controlled by two buttons on the case. Pressing the top button starts the timer running, and pressing the button a second time stops it, leaving the elapsed time displayed. A press of the second button then resets the stopwatch to zero. The second button is also used to record split times or lap times. When the split time button is pressed while the watch is running it allows the elapsed time to that point to be read, but the watch mechanism continues running to record total elapsed time. Pressing the split button a second time allows the watch to resume display of total time.

DL2209Mk04

1 x Arduino Mega 2560 R2
1 x ArduiNIX V3 Tube Driver Shield Kit
1 x IN-17×8 V1 Tube Board Kit
1 x Anode / Cathode Connector Cable Set
1 x DS3231 Precision RTC FeatherWing
1 x CR1220 12mm Coin Cell Battery
2 x Rocker Switch – SPST
5 x 10K Ohm
1 x Momentary Button – Panel Mount (Blue)
2 x Momentary Button – Panel Mount (Black)
1 x SparkFun ProtoShield
1 x 9V 1000mA Power Supply
1 x SparkFun Cerberus USB Cable

Arduino Mega 2560 R2

SN2 – 2
SN3 – 3
SN4 – 4
SN5 – 5
SN6 – 6
SN7 – 7
SN8 – 8
SN9 – 9
AN10 – 10
AN11 – 11
AN12 – 12
AN13 – 13
SDA – 20
SCL – 21
RO0 – 53
RO1 – 51
MB0 = 49
MB1 = 47
MB2 = 45
VIN – +3.3V
VIN – +5V
VIN – +9V
GND – GND

DL2209Mk04p.ino

/* ***** Don Luc Electronics © *****
Software Version Information
Project #21 - Nixie - Stopwatch - Mk04
21-04
DL2209Mk04p.ino
1 x Arduino Mega 2560 R2
1 x ArduiNIX V3 Tube Driver Shield Kit
1 x IN-17x8 V1 Tube Board Kit
1 x Anode / Cathode Connector Cable Set
1 x DS3231 Precision RTC FeatherWing
1 x CR1220 12mm Coin Cell Battery
2 x Rocker Switch - SPST
5 x 10K Ohm
1 x Momentary Button - Panel Mount (Blue)
2 x Momentary Button - Panel Mount (Black)
1 x 9V 1000mA Power Supply
1 x SparkFun Cerberus USB Cable
*/

// Include the Library Code
// Wire you to communicate with I2C/TWI devices
// Date and Time DS3231 RTC
#include "RTClib.h"

// SN74141 (1)
int ledPin_0_a = 2;                
int ledPin_0_b = 3;
int ledPin_0_c = 4;
int ledPin_0_d = 5;

// SN74141 (2)
int ledPin_1_a = 6;                
int ledPin_1_b = 7;
int ledPin_1_c = 8;
int ledPin_1_d = 9;

// Anode pins
int ledPin_a_1 = 10;
int ledPin_a_2 = 11;
int ledPin_a_3 = 12;
int ledPin_a_4 = 13;

// Fade
float fadeMax = 0.1f;
float fadeStep = 0.1f;
// Number Array
int NumberArray[8]={0,0,0,0,0,0,0,0};
int currNumberArray[8]={0,0,0,0,0,0,0,0};
float NumberArrayFadeInValue[8]={0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f};
float NumberArrayFadeOutValue[8]={5.0f,5.0f,5.0f,5.0f,5.0f,5.0f,5.0f,5.0f};

// Date and time functions using a DS3231 RTC
RTC_DS3231 RTC;

// Rocker Switch - SPST
// Rocker Switch 0
const int iRO0 = 53;
// State
int iRO0State = 0;
// Rocker Switch 1
const int iRO1 = 51;
// State
int iRO1State = 0;

// Momentary Button
const int iStartP = 49;
const int iStopP = 47;
const int iResetP = 45;

// Setting hours, minutes, secound and miliseconds to 0
int iH = 0;
int iM = 0;
int iS = 0;
int iMS = 0;
int iMSS = 0;

// Defines starting points
int iStart = 0;
int iStop1 = 0;
int iReset = 0;

// Get the high and low order values for hours,min,seconds. 
int lowerHours = 0;
int upperHours = 0;
int lowerMins = 0;
int upperMins = 0;
int lowerSeconds = 0;
int upperSeconds = 0;
int lowerMiliseconds = 0;
int upperMiliseconds = 0;

// Software Version Information
String sver = "21-04";

void loop() {

  // Read the state of the Switch value
  iRO1State = digitalRead(iRO1);
  
  // If it is the Switch State is HIGH
  if (iRO1State == HIGH) {
  
    // Stopwatch
    isStart();

  } else {

    // Date ans Time
    isTimeRTC();
    
  }

}

getDisplayFadeNumber.ino

// Display Fade Number
void DisplayFadeNumberString()
{
 
  // Anode channel 1 - numerals 0,4
  SetSN74141Chips(currNumberArray[0],currNumberArray[4]);   
  digitalWrite(ledPin_a_1, HIGH);   
  delay(NumberArrayFadeOutValue[0]);
  SetSN74141Chips(NumberArray[0],NumberArray[4]);   
  delay(NumberArrayFadeInValue[0]);
  digitalWrite(ledPin_a_1, LOW);
  
  // Anode channel 2 - numerals 1,5
  SetSN74141Chips(currNumberArray[1],currNumberArray[5]);   
  digitalWrite(ledPin_a_2, HIGH);   
  delay(NumberArrayFadeOutValue[1]);
  SetSN74141Chips(NumberArray[1],NumberArray[5]);   
  delay(NumberArrayFadeInValue[1]);
  digitalWrite(ledPin_a_2, LOW);
  
  // Anode channel 3 - numerals 2,6
  SetSN74141Chips(currNumberArray[2],currNumberArray[6]);   
  digitalWrite(ledPin_a_3, HIGH);   
  delay(NumberArrayFadeOutValue[2]);
  SetSN74141Chips(NumberArray[2],NumberArray[6]);   
  delay(NumberArrayFadeInValue[2]);
  digitalWrite(ledPin_a_3, LOW);
  
  // Anode channel 4 - numerals 3,7
  SetSN74141Chips(currNumberArray[3],currNumberArray[7]);   
  digitalWrite(ledPin_a_4, HIGH);   
  delay(NumberArrayFadeOutValue[3]);
  SetSN74141Chips(NumberArray[3],NumberArray[7]);   
  delay(NumberArrayFadeInValue[3]);
  digitalWrite(ledPin_a_4, LOW);
  
  // Loop thru and update all the arrays, and fades.
  for( int i = 0 ; i < 8 ; i ++ ) //equal to & of digits
  {
    if( NumberArray[i] != currNumberArray[i] )
    {
      NumberArrayFadeInValue[i] += fadeStep;
      NumberArrayFadeOutValue[i] -= fadeStep;
  
      if( NumberArrayFadeInValue[i] >= fadeMax )
      {
        NumberArrayFadeInValue[i] = 2.0f;
        NumberArrayFadeOutValue[i] = 4.0f; //affects the refresh cycle
        currNumberArray[i] = NumberArray[i];
      }
    }
  }
  
}

getRTCDS3231.ino

// DS3231 Precision RTC
// Setup RTC
void setupRTC() {

  // DS3231 Precision RTC   
  RTC.begin();
  if (! RTC.begin() ) {
    while (1) delay(10);
  }

  if (RTC.lostPower()) {
    
    // Following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // August 2, 2021 at 13:53:0 you would call:
    // RTC.adjust(DateTime(2022, 4, 26, 11, 39, 0));
    
  }
  
}
// Date ans Time - isTimeRTC
void isTimeRTC() {

  // Date and Time
  DateTime now = RTC.now();

  // Read the state of the Switch value
  iRO0State = digitalRead(iRO0);
  
  // If it is the Switch State is HIGH
  if (iRO0State == HIGH) {


    // Get the high and low order values for hours, minute, seconds
    int lowerHours = now.hour() % 10;
    int upperHours = now.hour() - lowerHours;
    int lowerMins = now.minute() % 10;
    int upperMins = now.minute() - lowerMins;
    int lowerSeconds = now.second() % 10;
    int upperSeconds = now.second() - lowerSeconds;
    
    // 10 >= hours, minute, seconds
    if( upperSeconds >= 10 )   upperSeconds = upperSeconds / 10;
    if( upperMins >= 10 )      upperMins = upperMins / 10;
    if( upperHours >= 10 )     upperHours = upperHours / 10;
    if( upperHours == 0 && lowerHours == 0 )
    {
      
      upperHours = 1;
      lowerHours = 2;
      
    }

    // Fill in the Number array used to display on the Nixie tubes
    NumberArray[7] = upperHours;
    NumberArray[6] = lowerHours;
    NumberArray[5] = 0;
    NumberArray[4] = upperMins;
    NumberArray[3] = lowerMins;
    NumberArray[2] = 0;
    NumberArray[1] = upperSeconds; 
    NumberArray[0] = lowerSeconds;

  } else {

    // Get the high and low order values for year, month, day
    int iYear = now.year() - 2000;
    int lowerYear = iYear % 10;
    int upperYear = iYear - lowerYear;
    int lowerMonth = now.month() % 10;
    int upperMonth = now.month() - lowerMonth;
    int lowerDay = now.day() % 10;
    int upperDay = now.day() - lowerDay;

    // 10 >= year, month, day
    if( upperDay >= 10 )   upperDay = upperDay / 10;
    if( upperMonth >= 10 )      upperMonth = upperMonth / 10;
    if( upperYear >= 10 )     upperYear = upperYear / 10;

    // Fill in the Number array used to display on the Nixie tubes
    NumberArray[7] = 2;
    NumberArray[6] = 0;
    NumberArray[5] = upperYear;
    NumberArray[4] = lowerYear;
    NumberArray[3] = upperMonth;
    NumberArray[2] = lowerMonth;
    NumberArray[1] = upperDay; 
    NumberArray[0] = lowerDay;
  
  }
  
  // Display
  DisplayFadeNumberString();
  
}

getSN74141.ino

// SN74141
// SN74141 : Truth Table
//D C B A #
//L,L,L,L 0
//L,L,L,H 1
//L,L,H,L 2
//L,L,H,H 3
//L,H,L,L 4
//L,H,L,H 5
//L,H,H,L 6
//L,H,H,H 7
//H,L,L,L 8
//H,L,L,H 9
// isSetupSN74141
void isSetupSN74141(){

  pinMode(ledPin_0_a, OUTPUT);      
  pinMode(ledPin_0_b, OUTPUT);      
  pinMode(ledPin_0_c, OUTPUT);      
  pinMode(ledPin_0_d, OUTPUT);    
  
  pinMode(ledPin_1_a, OUTPUT);      
  pinMode(ledPin_1_b, OUTPUT);      
  pinMode(ledPin_1_c, OUTPUT);      
  pinMode(ledPin_1_d, OUTPUT);      
  
  pinMode(ledPin_a_1, OUTPUT);      
  pinMode(ledPin_a_2, OUTPUT);      
  pinMode(ledPin_a_3, OUTPUT);   
  pinMode(ledPin_a_4, OUTPUT);    

}
// SetSN74141Chips
void SetSN74141Chips( int num2, int num1 )
{
  
  // Set defaults
  // Will display a zero.
  int a = 0;
  int b = 0;
  int c = 0;
  int d = 0;
  
  // Load the a,b,c,d.. to send to the SN74141 IC (1)
  switch( num1 )
  {
    case 0:
      a=0;
      b=0;
      c=0;
      d=0;
      break;
    case 1:
      a=1;
      b=0;
      c=0;
      d=0;
      break;
    case 2:
      a=0;
      b=1;
      c=0;
      d=0;
      break;
    case 3:
      a=1;
      b=1;
      c=0;
      d=0;
      break;
    case 4:
      a=0;
      b=0;
      c=1;
      d=0;
      break;
    case 5:
      a=1;
      b=0;
      c=1;
      d=0;
      break;
    case 6: 
      a=0;
      b=1;
      c=1;
      d=0;
      break;
    case 7:
      a=1;
      b=1;
      c=1;
      d=0;
      break;
    case 8:
      a=0;
      b=0;
      c=0;
      d=1;
      break;
    case 9:
      a=1;
      b=0;
      c=0;
      d=1;
      break;
    default:
      a=1;
      b=1;
      c=1;
      d=1;
      break;
  }  
  
  // Write to output pins.
  digitalWrite(ledPin_0_d, d);
  digitalWrite(ledPin_0_c, c);
  digitalWrite(ledPin_0_b, b);
  digitalWrite(ledPin_0_a, a);

  // Load the a,b,c,d.. to send to the SN74141 IC (2)
  switch( num2 )
  {
    case 0:
      a=0;
      b=0;
      c=0;
      d=0;
      break;
    case 1:
      a=1;
      b=0;
      c=0;
      d=0;
      break;
    case 2:
      a=0;
      b=1;
      c=0;
      d=0;
      break;
    case 3:
      a=1;
      b=1;
      c=0;
      d=0;
      break;
    case 4:
      a=0;
      b=0;
      c=1;
      d=0;
      break;
    case 5:
      a=1;
      b=0;
      c=1;
      d=0;
      break;
    case 6:
      a=0;
      b=1;
      c=1;
      d=0;
      break;
    case 7:
      a=1;
      b=1;
      c=1;
      d=0;
      break;
    case 8:
      a=0;
      b=0;
      c=0;
      d=1;
      break;
    case 9:
      a=1;
      b=0;
      c=0;
      d=1;
      break;
    default:
      a=1;
      b=1;
      c=1;
      d=1;
      break;
  }
  
  // Write to output pins
  digitalWrite(ledPin_1_d, d);
  digitalWrite(ledPin_1_c, c);
  digitalWrite(ledPin_1_b, b);
  digitalWrite(ledPin_1_a, a);
  
}

getStopwatch.ino

// Stopwatch
// Setup Stopwatch
void isSetupStopwatch(){

  // Switch
  pinMode(iRO0, INPUT);
  pinMode(iRO1, INPUT);

  // Momentary Button
  pinMode(iStartP, INPUT);
  pinMode(iStopP, INPUT);
  pinMode(iResetP, INPUT);
  
}
// Start
void isStart()
{

  // Reading buton state iStart
  iStart = digitalRead(iStartP);
  if(iStart == HIGH) 
  {

    // Calls the isStopWatch function
    isStopWatch();

 }

}
// Stop Watch
void isStopWatch()
{

  // Miliseconds
  iMS = iMS + 10;     
  if(iMS == 600)           
  {
   
    iMS = 0;
    iMSS = 0;
    iS = iS + 1;
    
  } else if (iMS == 60) { // 1

    iMSS = iMSS + 1;
    
  } else if (iMS == 120) { // 2

    iMSS = iMSS + 1;
    
  } else if (iMS == 180) { //3 

    iMSS = iMSS + 1;
    
  } else if (iMS == 240) { // 4

    iMSS = iMSS + 1;
    
  } else if (iMS == 300) { // 5

    iMSS = iMSS + 1;
    
  } else if (iMS == 360) { // 6

    iMSS = iMSS + 1;
    
  } else if (iMS == 420) { // 7

    iMSS = iMSS + 1;
    
  } else if (iMS == 480) { // 8

    iMSS = iMSS + 1;
    
  } else if (iMS == 540) { // 9

    iMSS = iMSS + 1;
    
  }
  // If state for counting up minutes
  if( iS == 60)
  { 
  
    iS = 0;
    iM = iM + 1;
    
  }
  // If state for counting up hours
  if( iM == 60)
  {  
    
    iM = 0;
    iH = iH + 01;
    
  }

  // Get the high and low order values for hours, minute, seconds, Miliseconds
  int lowerHours = iH % 10;
  int upperHours = iH - lowerHours;
  int lowerMins = iM % 10;
  int upperMins = iM - lowerMins;
  int lowerSeconds = iS % 10;
  int upperSeconds = iS - lowerSeconds;
  int lowerMiliseconds = iMSS;
  int upperMiliseconds = iMSS - lowerMiliseconds;
    
  // 10 >= hours, minute, seconds, Miliseconds
  if( upperSeconds >= 10 )   upperSeconds = upperSeconds / 10;
  if( upperMins >= 10 )      upperMins = upperMins / 10;
  if( upperHours >= 10 )     upperHours = upperHours / 10;

  // Fill in the Number array used to display on the Nixie tubes
  NumberArray[7] = upperHours;
  NumberArray[6] = lowerHours;
  NumberArray[5] = upperMins;
  NumberArray[4] = lowerMins;
  NumberArray[3] = upperSeconds;
  NumberArray[2] = lowerSeconds;
  NumberArray[1] = lowerMiliseconds; 
  NumberArray[0] = lowerMiliseconds;

  // Display
  DisplayFadeNumberString();
    
  // Reading buton state Stop
  iStop1 = digitalRead(iStopP);
  // Checking if button is pressed
  if(iStop1 == HIGH)
  {
    
    // Calls the isStopwatchStop function
    isStopwatchStop();
    
  }
  else
  {

    // Calls the isStopWatch function
    isStopWatch();
    
  }
  
}
// Stopwatch Stop
void isStopwatchStop()
{

  // Get the high and low order values for hours, minute, seconds, Miliseconds
  int lowerHours = iH % 10;
  int upperHours = iH - lowerHours;
  int lowerMins = iM % 10;
  int upperMins = iM - lowerMins;
  int lowerSeconds = iS % 10;
  int upperSeconds = iS - lowerSeconds;
  int lowerMiliseconds = iMSS;
  int upperMiliseconds = iMSS - lowerMiliseconds;
    
  // 10 >= hours, minute, seconds, Miliseconds
  if( upperSeconds >= 10 )   upperSeconds = upperSeconds / 10;
  if( upperMins >= 10 )      upperMins = upperMins / 10;
  if( upperHours >= 10 )     upperHours = upperHours / 10;
 
  // Fill in the Number array used to display on the Nixie tubes
  NumberArray[7] = upperHours;
  NumberArray[6] = lowerHours;
  NumberArray[5] = upperMins;
  NumberArray[4] = lowerMins;
  NumberArray[3] = upperSeconds;
  NumberArray[2] = lowerSeconds;
  NumberArray[1] = lowerMiliseconds; 
  NumberArray[0] = lowerMiliseconds;

  // Display
  DisplayFadeNumberString();
  
  // Reading buton state iStart
  iStart = digitalRead(iStartP);
  if(iStart == HIGH)
  {
    
    // Calls the isStopWatch function 
    isStopWatch();

  } 
  // Reading buton state
  iReset = digitalRead(iResetP);
  if(iReset == HIGH)
  {
   
     // Calls the isStopwatchReset function
     isStopwatchReset();
     loop();
   
  }
  if(iReset == LOW)
  {
    
    // Calls the isStopwatchStop function
    isStopwatchStop();
    
  }

}
// Stopwatch Reset
void isStopwatchReset()
{

   // Seting hours to 0
   iH = 0;
   // Seting minutes to 0
   iM = 0;
   // Seting seconds to 0
   iS = 0;
   // Seting miliseconds to 0
   iMS = 0;
   // Seting miliseconds to 0
   iMSS = 0;
   
   // Fill in the Number array used to display on the Nixie tubes
   NumberArray[7] = 0;
   NumberArray[6] = 0;
   NumberArray[5] = 0;
   NumberArray[4] = 0;
   NumberArray[3] = 0;
   NumberArray[2] = 0;
   NumberArray[1] = 0; 
   NumberArray[0] = 0;
   // Display
   DisplayFadeNumberString();
   // Exiting the program and returning to the point where entered the program
   return;
   
}

setup.ino

// Setup
void setup() {

  // isSetupSN74141
  isSetupSN74141();

  // Setup Stopwatch
  isSetupStopwatch();

  // Setup RTC
  setupRTC();

}

——

People can contact us: https://www.donluc.com/?page_id=1927

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
  • IoT
  • Robotics
  • Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
  • Unmanned Vehicles Terrestrial and Marine
  • Research & Development (R & D)

Instructor and E-Mentor

  • IoT
  • PIC Microcontrollers
  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics

Follow Us

J. Luc Paquin – Curriculum Vitae – 2022 English & Español
https://www.jlpconsultants.com/luc/

Web: https://www.donluc.com/
Web: https://www.jlpconsultants.com/
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/

Don Luc

Project #21 – Nixie – DS3231 Precision RTC – Mk03

——

#DonLucElectronics #DonLuc #NixieTube #Nixie #ArduiNIX #ArduinoUNO #Arduino #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant

——

DS3231 Precision RTC

——

DS3231 Precision RTC

——

DS3231 Precision RTC

——

DS3231 Precision RTC FeatherWing

The datasheet for the DS3231 explains that this part is an extremely accurate I²C – Integrated RTC TCXO – crystal. This Real Time Clock (RTC) is the most precise you can get in a small, low power package. Most RTC’s use an external 32kHz timing crystal that is used to keep time with low current draw. That’s all well and good, but those crystals have slight drift, particularly when the temperature changes, the temperature changes the oscillation frequency very slightly but it does add up. This RTC is in a beefy package because the crystal is inside the chip. And right next to the integrated crystal is a temperature sensor. That sensor compensates for the frequency changes by adding or removing clock ticks so that the time keeping stays on schedule.

This is the finest RTC you can get, and now we have it in a compact, breadboard friendly breakout. With a coin cell plugged into the back, you can get years of precision time keeping, even when main power is lost. Great for datalogging and clocks, or anything where you need to really know the time.

DL2209Mk03

1 x Arduino Mega 2560 R2
1 x ArduiNIX V3 Tube Driver Shield Kit
1 x IN-17×8 V1 Tube Board Kit
1 x Anode / Cathode Connector Cable Set
1 x DS3231 Precision RTC FeatherWing
1 x CR1220 12mm Coin Cell Battery
1 x Rocker Switch – SPST
1 x 10K Ohm
1 x SparkFun ProtoShield
1 x 9V 1000mA Power Supply
1 x SparkFun Cerberus USB Cable

Arduino Mega 2560 R2

SN2 – 2
SN3 – 3
SN4 – 4
SN5 – 5
SN6 – 6
SN7 – 7
SN8 – 8
SN9 – 9
AN10 – 10
AN11 – 11
AN12 – 12
AN13 – 13
VI14 – 14
VI15 – 15
SDA – 20
SCL – 21
RO0 – 53
VIN – +3.3V
VIN – +5V
VIN – +9V
GND – GND

DL2209Mk03p.ino

/* ***** Don Luc Electronics © *****
Software Version Information
Project #21 - Nixie - DS3231 Precision RTC - Mk03
21-03
DL2209Mk03p.ino
1 x Arduino Mega 2560 R2
1 x ArduiNIX V3 Tube Driver Shield Kit
1 x IN-17x8 V1 Tube Board Kit
1 x Anode / Cathode Connector Cable Set
1 x DS3231 Precision RTC FeatherWing
1 x CR1220 12mm Coin Cell Battery
1 x Rocker Switch - SPST
1 x 10K Ohm
1 x 9V 1000mA Power Supply
1 x SparkFun Cerberus USB Cable
*/

// Include the Library Code
// Wire you to communicate with I2C/TWI devices
// Date and Time DS3231 RTC
#include "RTClib.h"

// SN74141 (1)
int ledPin_0_a = 2;                
int ledPin_0_b = 3;
int ledPin_0_c = 4;
int ledPin_0_d = 5;

// SN74141 (2)
int ledPin_1_a = 6;                
int ledPin_1_b = 7;
int ledPin_1_c = 8;
int ledPin_1_d = 9;

// Anode pins
int ledPin_a_1 = 10;
int ledPin_a_2 = 11;
int ledPin_a_3 = 12;
int ledPin_a_4 = 13;

// NOTE: Grounding on virtual pins 14 and 15 
// (analog pins 0 and 1) will set the Hour and Mins.
int iVirtual14 = 14;
int iVirtual15 = 15;

// Fade
float fadeMax = 0.1f;
float fadeStep = 0.1f;
// Number Array
int NumberArray[8]={0,0,0,0,0,0,0,0};
int currNumberArray[8]={0,0,0,0,0,0,0,0};
float NumberArrayFadeInValue[8]={0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f};
float NumberArrayFadeOutValue[8]={5.0f,5.0f,5.0f,5.0f,5.0f,5.0f,5.0f,5.0f};

// Date and time functions using a DS3231 RTC
RTC_DS3231 RTC;

// Rocker Switch - SPST
int iRO0 = 53;
// State
int iRO0State = 0;

// Software Version Information
String sver = "21-03";

void loop() {

  // timeRTC
  timeRTC();

}

getDisplayFadeNumber.ino

// Display Fade Number
void DisplayFadeNumberString()
{
 
  // Anode channel 1 - numerals 0,4
  SetSN74141Chips(currNumberArray[0],currNumberArray[4]);   
  digitalWrite(ledPin_a_1, HIGH);   
  delay(NumberArrayFadeOutValue[0]);
  SetSN74141Chips(NumberArray[0],NumberArray[4]);   
  delay(NumberArrayFadeInValue[0]);
  digitalWrite(ledPin_a_1, LOW);
  
  // Anode channel 2 - numerals 1,5
  SetSN74141Chips(currNumberArray[1],currNumberArray[5]);   
  digitalWrite(ledPin_a_2, HIGH);   
  delay(NumberArrayFadeOutValue[1]);
  SetSN74141Chips(NumberArray[1],NumberArray[5]);   
  delay(NumberArrayFadeInValue[1]);
  digitalWrite(ledPin_a_2, LOW);
  
  // Anode channel 3 - numerals 2,6
  SetSN74141Chips(currNumberArray[2],currNumberArray[6]);   
  digitalWrite(ledPin_a_3, HIGH);   
  delay(NumberArrayFadeOutValue[2]);
  SetSN74141Chips(NumberArray[2],NumberArray[6]);   
  delay(NumberArrayFadeInValue[2]);
  digitalWrite(ledPin_a_3, LOW);
  
  // Anode channel 4 - numerals 3,7
  SetSN74141Chips(currNumberArray[3],currNumberArray[7]);   
  digitalWrite(ledPin_a_4, HIGH);   
  delay(NumberArrayFadeOutValue[3]);
  SetSN74141Chips(NumberArray[3],NumberArray[7]);   
  delay(NumberArrayFadeInValue[3]);
  digitalWrite(ledPin_a_4, LOW);
  
  // Loop thru and update all the arrays, and fades.
  for( int i = 0 ; i < 8 ; i ++ ) //equal to & of digits
  {
    if( NumberArray[i] != currNumberArray[i] )
    {
      NumberArrayFadeInValue[i] += fadeStep;
      NumberArrayFadeOutValue[i] -= fadeStep;
  
      if( NumberArrayFadeInValue[i] >= fadeMax )
      {
        NumberArrayFadeInValue[i] = 2.0f;
        NumberArrayFadeOutValue[i] = 4.0f; //affects the refresh cycle
        currNumberArray[i] = NumberArray[i];
      }
    }
  }
  
}

getRTCDS3231.ino

// DS3231 Precision RTC
// Setup RTC
void setupRTC() {

  // DS3231 Precision RTC   
  RTC.begin();
  if (! RTC.begin() ) {
    while (1) delay(10);
  }

  if (RTC.lostPower()) {
    
    // Following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // August 2, 2021 at 13:53:0 you would call:
    // RTC.adjust(DateTime(2022, 4, 26, 11, 39, 0));
    
  }
  
}
// timeRTC
void timeRTC() {

  // Date and Time
  DateTime now = RTC.now();

  // Read the state of the Switch value
  iRO0State = digitalRead(iRO0);
  
  // If it is the Switch State is HIGH
  if (iRO0State == HIGH) {


    // Get the high and low order values for hours, minute, seconds
    int lowerHours = now.hour() % 10;
    int upperHours = now.hour() - lowerHours;
    int lowerMins = now.minute() % 10;
    int upperMins = now.minute() - lowerMins;
    int lowerSeconds = now.second() % 10;
    int upperSeconds = now.second() - lowerSeconds;
    
    // 10 >= hours, minute, seconds
    if( upperSeconds >= 10 )   upperSeconds = upperSeconds / 10;
    if( upperMins >= 10 )      upperMins = upperMins / 10;
    if( upperHours >= 10 )     upperHours = upperHours / 10;
    if( upperHours == 0 && lowerHours == 0 )
    {
      
      upperHours = 1;
      lowerHours = 2;
      
    }

    // Fill in the Number array used to display on the Nixie tubes
    NumberArray[7] = upperHours;
    NumberArray[6] = lowerHours;
    NumberArray[5] = 0;
    NumberArray[4] = upperMins;
    NumberArray[3] = lowerMins;
    NumberArray[2] = 0;
    NumberArray[1] = upperSeconds; 
    NumberArray[0] = lowerSeconds;

  } else {

    // Get the high and low order values for year, month, day
    int iYear = now.year() - 2000;
    int lowerYear = iYear % 10;
    int upperYear = iYear - lowerYear;
    int lowerMonth = now.month() % 10;
    int upperMonth = now.month() - lowerMonth;
    int lowerDay = now.day() % 10;
    int upperDay = now.day() - lowerDay;

    // 10 >= year, month, day
    if( upperDay >= 10 )   upperDay = upperDay / 10;
    if( upperMonth >= 10 )      upperMonth = upperMonth / 10;
    if( upperYear >= 10 )     upperYear = upperYear / 10;

    // Fill in the Number array used to display on the Nixie tubes
    NumberArray[7] = 2;
    NumberArray[6] = 0;
    NumberArray[5] = upperYear;
    NumberArray[4] = lowerYear;
    NumberArray[3] = upperMonth;
    NumberArray[2] = lowerMonth;
    NumberArray[1] = upperDay; 
    NumberArray[0] = lowerDay;
  
  }
  
  // Display
  DisplayFadeNumberString();
  
}

getSN74141.ino

// SN74141
// SN74141 : Truth Table
//D C B A #
//L,L,L,L 0
//L,L,L,H 1
//L,L,H,L 2
//L,L,H,H 3
//L,H,L,L 4
//L,H,L,H 5
//L,H,H,L 6
//L,H,H,H 7
//H,L,L,L 8
//H,L,L,H 9
// isSetupSN74141
void isSetupSN74141(){

  pinMode(ledPin_0_a, OUTPUT);      
  pinMode(ledPin_0_b, OUTPUT);      
  pinMode(ledPin_0_c, OUTPUT);      
  pinMode(ledPin_0_d, OUTPUT);    
  
  pinMode(ledPin_1_a, OUTPUT);      
  pinMode(ledPin_1_b, OUTPUT);      
  pinMode(ledPin_1_c, OUTPUT);      
  pinMode(ledPin_1_d, OUTPUT);      
  
  pinMode(ledPin_a_1, OUTPUT);      
  pinMode(ledPin_a_2, OUTPUT);      
  pinMode(ledPin_a_3, OUTPUT);   
  pinMode(ledPin_a_4, OUTPUT);    
 
  // NOTE: Grounding on virtual pins 14 and 15 
  // (analog pins 0 and 1) will set the Hour and Mins.
  // Set the vertual pin 14 (pin 0 on the analog inputs )
  pinMode( iVirtual14, INPUT );
  // Set pin 14 as a pull up resistor.
  digitalWrite(iVirtual14, HIGH);
  // Set the vertual pin 15 (pin 1 on the analog inputs )
  pinMode( iVirtual15, INPUT );
  // Set pin 15 as a pull up resistor.
  digitalWrite(iVirtual15, HIGH);
  
}
// SetSN74141Chips
void SetSN74141Chips( int num2, int num1 )
{
  
  // Set defaults
  // Will display a zero.
  int a = 0;
  int b = 0;
  int c = 0;
  int d = 0;
  
  // Load the a,b,c,d.. to send to the SN74141 IC (1)
  switch( num1 )
  {
    case 0:
      a=0;
      b=0;
      c=0;
      d=0;
      break;
    case 1:
      a=1;
      b=0;
      c=0;
      d=0;
      break;
    case 2:
      a=0;
      b=1;
      c=0;
      d=0;
      break;
    case 3:
      a=1;
      b=1;
      c=0;
      d=0;
      break;
    case 4:
      a=0;
      b=0;
      c=1;
      d=0;
      break;
    case 5:
      a=1;
      b=0;
      c=1;
      d=0;
      break;
    case 6: 
      a=0;
      b=1;
      c=1;
      d=0;
      break;
    case 7:
      a=1;
      b=1;
      c=1;
      d=0;
      break;
    case 8:
      a=0;
      b=0;
      c=0;
      d=1;
      break;
    case 9:
      a=1;
      b=0;
      c=0;
      d=1;
      break;
    default:
      a=1;
      b=1;
      c=1;
      d=1;
      break;
  }  
  
  // Write to output pins.
  digitalWrite(ledPin_0_d, d);
  digitalWrite(ledPin_0_c, c);
  digitalWrite(ledPin_0_b, b);
  digitalWrite(ledPin_0_a, a);

  // Load the a,b,c,d.. to send to the SN74141 IC (2)
  switch( num2 )
  {
    case 0:
      a=0;
      b=0;
      c=0;
      d=0;
      break;
    case 1:
      a=1;
      b=0;
      c=0;
      d=0;
      break;
    case 2:
      a=0;
      b=1;
      c=0;
      d=0;
      break;
    case 3:
      a=1;
      b=1;
      c=0;
      d=0;
      break;
    case 4:
      a=0;
      b=0;
      c=1;
      d=0;
      break;
    case 5:
      a=1;
      b=0;
      c=1;
      d=0;
      break;
    case 6:
      a=0;
      b=1;
      c=1;
      d=0;
      break;
    case 7:
      a=1;
      b=1;
      c=1;
      d=0;
      break;
    case 8:
      a=0;
      b=0;
      c=0;
      d=1;
      break;
    case 9:
      a=1;
      b=0;
      c=0;
      d=1;
      break;
    default:
      a=1;
      b=1;
      c=1;
      d=1;
      break;
  }
  
  // Write to output pins
  digitalWrite(ledPin_1_d, d);
  digitalWrite(ledPin_1_c, c);
  digitalWrite(ledPin_1_b, b);
  digitalWrite(ledPin_1_a, a);
  
}

setup.ino

// Setup
void setup() {

  // isSetupSN74141
  isSetupSN74141();

  // Switch
  pinMode(iRO0, INPUT);

  // Setup RTC
  setupRTC();

}

——

People can contact us: https://www.donluc.com/?page_id=1927

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
  • IoT
  • Robotics
  • Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
  • Unmanned Vehicles Terrestrial and Marine
  • Research & Development (R & D)

Instructor and E-Mentor

  • IoT
  • PIC Microcontrollers
  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics

Follow Us

J. Luc Paquin – Curriculum Vitae – 2022 English & Español
https://www.jlpconsultants.com/luc/

Web: https://www.donluc.com/
Web: https://www.jlpconsultants.com/
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/

Don Luc

Project #21 – Nixie – ArduiNIX – Mk02

——

#DonLucElectronics #DonLuc #NixieTube #Nixie #ArduiNIX #ArduinoUNO #Arduino #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant

——

ArduiNIX

——

ArduiNIX

——

ArduiNIX

——

ArduiNIX

——

ArduiNIX

The ArduiNIX is an Arduino compatible shield which plugs right onto the top of the Arduino UNO board. ArduiNIX takes care of stepping power from 9 VDC wall adapter power supply up to a maximum of approximately 250 VDC to drive any and all Nixie tubes. ArduiNIX also provides Multiplexed display for up to 80 elements by using 4 anode channels and 20 cathode channels. Multiplexing increases the life expectancy of your Nixie tube investment.

Not only does the ArduiNIX provide a Nixie tube platform for standard clock functions, but it is also user programmable, meaning if you can program it using the arduino environment, you can make it happen on your Nixie display. Take special care when working with the ArduiNIX. The ArduiNIX Shield operates at high voltages. Be careful when handling it while it’s powered up. Normally the Arduino is safe to handle, but when used in conjunction with the ArduiNIX, voltages in excess of 200 volts may be achieved. Use caution. An IN-17 x 8 display board, and 8 x Russian IN-17 Nixie tubes.

DL2209Mk02

1 x Arduino UNO
1 x ArduiNIX V3 Tube Driver Shield Kit
1 x IN-17×8 V1 Tube Board Kit
1 x Anode / Cathode Connector Cable Set
1 x 9V 1000mA Power Supply
1 x SparkFun Cerberus USB Cable

Arduino UNO

SN2 – 2
SN3 – 3
SN4 – 4
SN5 – 5
SN6 – 6
SN7 – 7
SN8 – 8
SN9 – 9
AN10 – 10
AN11 – 11
AN12 – 12
AN13 – 13
VI14 – 14
VI15 – 15
VIN – +9V
GND – GND

DL2209Mk02p.ino

/* ***** Don Luc Electronics © *****
Software Version Information
Project #21 - Nixie - ArduiNIX - Mk02
21-02
DL2209Mk02p.ino
1 x Arduino UNO
1 x ArduiNIX V3 Tube Driver Shield Kit
1 x IN-17x8 V1 Tube Board Kit
1 x Anode / Cathode Connector Cable Set
1 x 9V 1000mA Power Supply
1 x SparkFun Cerberus USB Cable
*/

// Include the Library Code

// SN74141 (1)
int ledPin_0_a = 2;                
int ledPin_0_b = 3;
int ledPin_0_c = 4;
int ledPin_0_d = 5;

// SN74141 (2)
int ledPin_1_a = 6;                
int ledPin_1_b = 7;
int ledPin_1_c = 8;
int ledPin_1_d = 9;

// Anode pins
int ledPin_a_1 = 10;
int ledPin_a_2 = 11;
int ledPin_a_3 = 12;
int ledPin_a_4 = 13;

// NOTE: Grounding on virtual pins 14 and 15 
// (analog pins 0 and 1) will set the Hour and Mins.
int iVirtual14 = 14;
int iVirtual15 = 15;

// Fade
float fadeMax = 0.1f;
float fadeStep = 0.1f;
// Number Array
int NumberArray[8]={0,0,0,0,0,0,0,0};
int currNumberArray[8]={0,0,0,0,0,0,0,0};
float NumberArrayFadeInValue[8]={0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f};
float NumberArrayFadeOutValue[8]={5.0f,5.0f,5.0f,5.0f,5.0f,5.0f,5.0f,5.0f};

// Defines
// Sub seconds
long SSECS = 100;
// Milliseconds in a Sec
long SECS = 60;
// 60 Seconds in a Min.
long MINS = 60;
// 60 Mins in an hour
long HOURS = 60 * MINS;
// 24 Hours in a day. > Note: change the 24 to a 12 for non military time.
long DAYS = 12 * HOURS; 

// Time from when we started
long runTime = 0;

// Default time sets. clock will start at 12:34:00.
// This is so we can count the correct order of tubes.
long clockHourSet;
long clockMinSet;
long clockSecSet;
//long clockSSecSet;

int HourButtonPressed = false;
int MinButtonPressed = false;

// Software Version Information
String sver = "21-02";

void loop() {

  // Time
  isTime();
  
}

getDisplayFadeNumber.ino

// Display Fade Number
void DisplayFadeNumberString()
{
 
  // Anode channel 1 - numerals 0,4
  SetSN74141Chips(currNumberArray[0],currNumberArray[4]);   
  digitalWrite(ledPin_a_1, HIGH);   
  delay(NumberArrayFadeOutValue[0]);
  SetSN74141Chips(NumberArray[0],NumberArray[4]);   
  delay(NumberArrayFadeInValue[0]);
  digitalWrite(ledPin_a_1, LOW);
  
    // Anode channel 2 - numerals 1,5
  SetSN74141Chips(currNumberArray[1],currNumberArray[5]);   
  digitalWrite(ledPin_a_2, HIGH);   
  delay(NumberArrayFadeOutValue[1]);
  SetSN74141Chips(NumberArray[1],NumberArray[5]);   
  delay(NumberArrayFadeInValue[1]);
  digitalWrite(ledPin_a_2, LOW);
  
   // Anode channel 3 - numerals 2,6
  SetSN74141Chips(currNumberArray[2],currNumberArray[6]);   
  digitalWrite(ledPin_a_3, HIGH);   
  delay(NumberArrayFadeOutValue[2]);
  SetSN74141Chips(NumberArray[2],NumberArray[6]);   
  delay(NumberArrayFadeInValue[2]);
  digitalWrite(ledPin_a_3, LOW);
  
     // Anode channel 4 - numerals 3,7
  SetSN74141Chips(currNumberArray[3],currNumberArray[7]);   
  digitalWrite(ledPin_a_4, HIGH);   
  delay(NumberArrayFadeOutValue[3]);
  SetSN74141Chips(NumberArray[3],NumberArray[7]);   
  delay(NumberArrayFadeInValue[3]);
  digitalWrite(ledPin_a_4, LOW);
  
  // Loop thru and update all the arrays, and fades.
  for( int i = 0 ; i < 8 ; i ++ ) //equal to & of digits
  {
    if( NumberArray[i] != currNumberArray[i] )
    {
      NumberArrayFadeInValue[i] += fadeStep;
      NumberArrayFadeOutValue[i] -= fadeStep;
  
      if( NumberArrayFadeInValue[i] >= fadeMax )
      {
        NumberArrayFadeInValue[i] = 2.0f;
        NumberArrayFadeOutValue[i] = 4.0f; //affects the refresh cycle
        currNumberArray[i] = NumberArray[i];
      }
    }
  }
  
}

getSN74141.ino

// SN74141
// SN74141 : Truth Table
//D C B A #
//L,L,L,L 0
//L,L,L,H 1
//L,L,H,L 2
//L,L,H,H 3
//L,H,L,L 4
//L,H,L,H 5
//L,H,H,L 6
//L,H,H,H 7
//H,L,L,L 8
//H,L,L,H 9
// isSetupSN74141
void isSetupSN74141(){

  pinMode(ledPin_0_a, OUTPUT);      
  pinMode(ledPin_0_b, OUTPUT);      
  pinMode(ledPin_0_c, OUTPUT);      
  pinMode(ledPin_0_d, OUTPUT);    
  
  pinMode(ledPin_1_a, OUTPUT);      
  pinMode(ledPin_1_b, OUTPUT);      
  pinMode(ledPin_1_c, OUTPUT);      
  pinMode(ledPin_1_d, OUTPUT);      
  
  pinMode(ledPin_a_1, OUTPUT);      
  pinMode(ledPin_a_2, OUTPUT);      
  pinMode(ledPin_a_3, OUTPUT);   
  pinMode(ledPin_a_4, OUTPUT);    
 
  // NOTE: Grounding on virtual pins 14 and 15 
  // (analog pins 0 and 1) will set the Hour and Mins.
  // Set the vertual pin 14 (pin 0 on the analog inputs )
  pinMode( iVirtual14, INPUT );
  // Set pin 14 as a pull up resistor.
  digitalWrite(iVirtual14, HIGH);
  // Set the vertual pin 15 (pin 1 on the analog inputs )
  pinMode( iVirtual15, INPUT );
  // Set pin 15 as a pull up resistor.
  digitalWrite(iVirtual15, HIGH);
  
}
// SetSN74141Chips
void SetSN74141Chips( int num2, int num1 )
{
  
  // Set defaults
  // Will display a zero.
  int a = 0;
  int b = 0;
  int c = 0;
  int d = 0;
  
  // Load the a,b,c,d.. to send to the SN74141 IC (1)
  switch( num1 )
  {
    case 0:
      a=0;
      b=0;
      c=0;
      d=0;
      break;
    case 1:
      a=1;
      b=0;
      c=0;
      d=0;
      break;
    case 2:
      a=0;
      b=1;
      c=0;
      d=0;
      break;
    case 3:
      a=1;
      b=1;
      c=0;
      d=0;
      break;
    case 4:
      a=0;
      b=0;
      c=1;
      d=0;
      break;
    case 5:
      a=1;
      b=0;
      c=1;
      d=0;
      break;
    case 6: 
      a=0;
      b=1;
      c=1;
      d=0;
      break;
    case 7:
      a=1;
      b=1;
      c=1;
      d=0;
      break;
    case 8:
      a=0;
      b=0;
      c=0;
      d=1;
      break;
    case 9:
      a=1;
      b=0;
      c=0;
      d=1;
      break;
    default:
      a=1;
      b=1;
      c=1;
      d=1;
      break;
  }  
  
  // Write to output pins.
  digitalWrite(ledPin_0_d, d);
  digitalWrite(ledPin_0_c, c);
  digitalWrite(ledPin_0_b, b);
  digitalWrite(ledPin_0_a, a);

  // Load the a,b,c,d.. to send to the SN74141 IC (2)
  switch( num2 )
  {
    case 0:
      a=0;
      b=0;
      c=0;
      d=0;
      break;
    case 1:
      a=1;
      b=0;
      c=0;
      d=0;
      break;
    case 2:
      a=0;
      b=1;
      c=0;
      d=0;
      break;
    case 3:
      a=1;
      b=1;
      c=0;
      d=0;
      break;
    case 4:
      a=0;
      b=0;
      c=1;
      d=0;
      break;
    case 5:
      a=1;
      b=0;
      c=1;
      d=0;
      break;
    case 6:
      a=0;
      b=1;
      c=1;
      d=0;
      break;
    case 7:
      a=1;
      b=1;
      c=1;
      d=0;
      break;
    case 8:
      a=0;
      b=0;
      c=0;
      d=1;
      break;
    case 9:
      a=1;
      b=0;
      c=0;
      d=1;
      break;
    default:
      a=1;
      b=1;
      c=1;
      d=1;
      break;
  }
  
  // Write to output pins
  digitalWrite(ledPin_1_d, d);
  digitalWrite(ledPin_1_c, c);
  digitalWrite(ledPin_1_b, b);
  digitalWrite(ledPin_1_a, a);
  
}

getTime.ino

// Time
void isTime(){

  // Get milliseconds.
  runTime = millis();
  //int ssTime = millis();
  
  int hourInput = digitalRead(iVirtual14);  
  int minInput  = digitalRead(iVirtual15);

  if( hourInput == 0 )
    HourButtonPressed = true;
  if( minInput == 0 )
    MinButtonPressed = true;
  if( HourButtonPressed == true && hourInput == 1 )
  {
    clockHourSet++;
    HourButtonPressed = false;
  }
  if( MinButtonPressed == true && minInput == 1 )
  {
    clockMinSet++;
    MinButtonPressed = false;
  }

  // Get time in seconds.
  // Change this value to speed up or
  // slow down the clock, set to smaller number such as 10, 1, or 100 for debugging
  long time = (runTime) / 1000;
  int sstime = (runTime) / 10;
  // Set time based on offset..
  // long hbump = 60*60*clockHourSet;
  //long sbump = 60*60*60*clockHourSet; //change hourset to secondset
  long hbump = 60*60*clockHourSet;
  long mbump = 60*clockMinSet;
  time += mbump + hbump;

  // Convert time to days,hours,mins,seconds
  long days  = time / DAYS;    time -= days  * DAYS; 
  long hours = time / HOURS;   time -= hours * HOURS; 
  long minutes  = time / MINS;    time -= minutes  * MINS; 
  long seconds  = time;      
//  long sseconds  = 76;// time -= seconds  * SECS;
  long sseconds  = runTime / SECS; time -= sseconds  * SECS; 

  // Get the high and low order values for hours,min,seconds. 
  int lowerHours = hours % 10;
  int upperHours = hours - lowerHours;
  int lowerMins = minutes % 10;
  int upperMins = minutes - lowerMins;
  int lowerSeconds = seconds % 10;
  int upperSeconds = seconds - lowerSeconds;
  int lowerSSeconds = sseconds % 10;
  //- lowerSSeconds;
  int upperSSeconds = lowerSSeconds % 10; upperSSeconds = upperSSeconds /10;
  
  if( upperSSeconds >= 10 )  upperSSeconds = upperSSeconds / 10;
  if( upperSeconds >= 10 )   upperSeconds = upperSeconds / 10;
  if( upperMins >= 10 )      upperMins = upperMins / 10;
  if( upperHours >= 10 )     upperHours = upperHours / 10;
 
  if( upperHours == 0 && lowerHours == 0 )
  {
    upperHours = 1;
    lowerHours = 2;
  }
  
  // Fill in the Number array used to display on the tubes.
  
  NumberArray[7] = upperHours;
  NumberArray[6] = lowerHours;
  NumberArray[5] = upperMins;
  NumberArray[4] = lowerMins;
  NumberArray[3] = upperSeconds;  
  NumberArray[2] = lowerSeconds;
  NumberArray[1] = lowerSSeconds; //upperSSeconds;  
  NumberArray[0] = lowerSSeconds; //lowerSSeconds;
  
  Serial.print(lowerSSeconds);
  Serial.println();
  // Display.
  //DisplayFadeNumberString();
  // Display.
  DisplayFadeNumberString();
  
}

setup.ino

// Setup
void setup() {

  // isSetupSN74141
  isSetupSN74141();

  // Open serial communications
 Serial.begin(9600);

}

——

People can contact us: https://www.donluc.com/?page_id=1927

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
  • IoT
  • Robotics
  • Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
  • Unmanned Vehicles Terrestrial and Marine
  • Research & Development (R & D)

Instructor and E-Mentor

  • IoT
  • PIC Microcontrollers
  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics

Follow Us

J. Luc Paquin – Curriculum Vitae – 2022 English & Español
https://www.jlpconsultants.com/luc/

Web: https://www.donluc.com/
Web: https://www.jlpconsultants.com/
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/

Don Luc

Project #21 – Nixie – Nixie Tube – Mk01

——

#DonLucElectronics #DonLuc #NixieTube #Nixie #ArduiNIX #ArduinoUNO #Arduino #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant

——

Nixie Tube

——

Nixie Tube

——

Nixie Tube

——

Nixie Tube

A Nixie tube, or cold cathode display, is an electronic device used for displaying numerals or other information using glow discharge. The glass tube contains a wire-mesh anode and multiple cathodes, shaped like numerals or other symbols. Applying power to one cathode surrounds it with an orange glow discharge. The tube is filled with a gas at low pressure.

The early Nixie displays were made by a small vacuum tube manufacturer called Haydu Brothers Laboratories, and introduced in 1955 by Burroughs Corporation, who purchased Haydu. The name Nixie was derived by Burroughs from “NIX I”, an abbreviation of “Numeric Indicator eXperimental No. 1”, although this may have been a backronym designed to justify the evocation of the mythical creature with this name.

Citing dissatisfaction with the aesthetics of modern digital displays and a nostalgic fondness for the styling of obsolete technology, significant numbers of electronics enthusiasts have shown interest in reviving Nixies.

DL2209Mk01

1 x Arduino UNO
1 x ArduiNIX V3 Tube Driver Shield Kit
1 x 9V 1000mA Power Supply
1 x SparkFun Cerberus USB Cable

Arduino UNO

SN2 – 2
SN3 – 3
SN4 – 4
SN5 – 5
SN6 – 6
SN7 – 7
SN8 – 8
SN9 – 9
AN10 – 10
AN11 – 11
AN12 – 12
AN13 – 13
VI14 – 14
VI15 – 15
VIN – +9V
GND – GND

DL2209Mk01p.ino

/* ***** Don Luc Electronics © *****
Software Version Information
Project #21 - Nixie - Nixie Tube - Mk01
21-01
DL2209Mk01p.ino
1 x Arduino UNO
1 x ArduiNIX V3 Tube Driver Shield Kit
1 x 9V 1000mA Power Supply
1 x SparkFun Cerberus USB Cable
*/

// Include the Library Code

// SN74141 (1)
int ledPin_0_a = 2;                
int ledPin_0_b = 3;
int ledPin_0_c = 4;
int ledPin_0_d = 5;

// SN74141 (2)
int ledPin_1_a = 6;                
int ledPin_1_b = 7;
int ledPin_1_c = 8;
int ledPin_1_d = 9;

// Anode pins
int ledPin_a_1 = 10;
int ledPin_a_2 = 11;
int ledPin_a_3 = 12;
int ledPin_a_4 = 13;

// NOTE: Grounding on virtual pins 14 and 15 
// (analog pins 0 and 1) will set the Hour and Mins.
int iVirtual14 = 14;
int iVirtual15 = 15;

// Fade
float fadeMax = 0.1f;
float fadeStep = 0.1f;
// Number Array
int NumberArray[8]={0,0,0,0,0,0,0,0};
int currNumberArray[8]={0,0,0,0,0,0,0,0};
float NumberArrayFadeInValue[8]={0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f};
float NumberArrayFadeOutValue[8]={5.0f,5.0f,5.0f,5.0f,5.0f,5.0f,5.0f,5.0f};

// Defines
// Sub seconds
long SSECS = 100;
// Milliseconds in a Sec
long SECS = 60;
// 60 Seconds in a Min.
long MINS = 60;
// 60 Mins in an hour
long HOURS = 60 * MINS;
// 24 Hours in a day. > Note: change the 24 to a 12 for non military time.
long DAYS = 12 * HOURS; 

// Time from when we started
long runTime = 0;

// Default time sets. clock will start at 12:34:00.
// This is so we can count the correct order of tubes.
long clockHourSet = 12;
long clockMinSet  = 34;
long clockSecSet  = 56;
long clockSSecSet  = 12;

int HourButtonPressed = false;
int MinButtonPressed = false;

// Software Version Information
String sver = "21-01";

void loop() {

  // Time
  isTime();
  
}

getDisplayFadeNumber.ino

// Display Fade Number
void DisplayFadeNumberString()
{
 
  // Anode channel 1 - numerals 0,4
  SetSN74141Chips(currNumberArray[0],currNumberArray[4]);   
  digitalWrite(ledPin_a_1, HIGH);   
  delay(NumberArrayFadeOutValue[0]);
  SetSN74141Chips(NumberArray[0],NumberArray[4]);   
  delay(NumberArrayFadeInValue[0]);
  digitalWrite(ledPin_a_1, LOW);
  
    // Anode channel 2 - numerals 1,5
  SetSN74141Chips(currNumberArray[1],currNumberArray[5]);   
  digitalWrite(ledPin_a_2, HIGH);   
  delay(NumberArrayFadeOutValue[1]);
  SetSN74141Chips(NumberArray[1],NumberArray[5]);   
  delay(NumberArrayFadeInValue[1]);
  digitalWrite(ledPin_a_2, LOW);
  
   // Anode channel 3 - numerals 2,6
  SetSN74141Chips(currNumberArray[2],currNumberArray[6]);   
  digitalWrite(ledPin_a_3, HIGH);   
  delay(NumberArrayFadeOutValue[2]);
  SetSN74141Chips(NumberArray[2],NumberArray[6]);   
  delay(NumberArrayFadeInValue[2]);
  digitalWrite(ledPin_a_3, LOW);
  
     // Anode channel 4 - numerals 3,7
  SetSN74141Chips(currNumberArray[3],currNumberArray[7]);   
  digitalWrite(ledPin_a_4, HIGH);   
  delay(NumberArrayFadeOutValue[3]);
  SetSN74141Chips(NumberArray[3],NumberArray[7]);   
  delay(NumberArrayFadeInValue[3]);
  digitalWrite(ledPin_a_4, LOW);
  
  // Loop thru and update all the arrays, and fades.
  for( int i = 0 ; i < 8 ; i ++ ) //equal to & of digits
  {
    if( NumberArray[i] != currNumberArray[i] )
    {
      NumberArrayFadeInValue[i] += fadeStep;
      NumberArrayFadeOutValue[i] -= fadeStep;
  
      if( NumberArrayFadeInValue[i] >= fadeMax )
      {
        NumberArrayFadeInValue[i] = 2.0f;
        NumberArrayFadeOutValue[i] = 4.0f; //affects the refresh cycle
        currNumberArray[i] = NumberArray[i];
      }
    }
  }
  
}

getSN74141.ino

// SN74141
// SN74141 : Truth Table
//D C B A #
//L,L,L,L 0
//L,L,L,H 1
//L,L,H,L 2
//L,L,H,H 3
//L,H,L,L 4
//L,H,L,H 5
//L,H,H,L 6
//L,H,H,H 7
//H,L,L,L 8
//H,L,L,H 9
// isSetupSN74141
void isSetupSN74141(){

  pinMode(ledPin_0_a, OUTPUT);      
  pinMode(ledPin_0_b, OUTPUT);      
  pinMode(ledPin_0_c, OUTPUT);      
  pinMode(ledPin_0_d, OUTPUT);    
  
  pinMode(ledPin_1_a, OUTPUT);      
  pinMode(ledPin_1_b, OUTPUT);      
  pinMode(ledPin_1_c, OUTPUT);      
  pinMode(ledPin_1_d, OUTPUT);      
  
  pinMode(ledPin_a_1, OUTPUT);      
  pinMode(ledPin_a_2, OUTPUT);      
  pinMode(ledPin_a_3, OUTPUT);   
  pinMode(ledPin_a_4, OUTPUT);    
 
  // NOTE: Grounding on virtual pins 14 and 15 
  // (analog pins 0 and 1) will set the Hour and Mins.
  // Set the vertual pin 14 (pin 0 on the analog inputs )
  pinMode( iVirtual14, INPUT );
  // Set pin 14 as a pull up resistor.
  digitalWrite(iVirtual14, HIGH);
  // Set the vertual pin 15 (pin 1 on the analog inputs )
  pinMode( iVirtual15, INPUT );
  // Set pin 15 as a pull up resistor.
  digitalWrite(iVirtual15, HIGH);
  
}
// SetSN74141Chips
void SetSN74141Chips( int num2, int num1 )
{
  
  // Set defaults
  // Will display a zero.
  int a = 0;
  int b = 0;
  int c = 0;
  int d = 0;
  
  // Load the a,b,c,d.. to send to the SN74141 IC (1)
  switch( num1 )
  {
    case 0:
      a=0;
      b=0;
      c=0;
      d=0;
      break;
    case 1:
      a=1;
      b=0;
      c=0;
      d=0;
      break;
    case 2:
      a=0;
      b=1;
      c=0;
      d=0;
      break;
    case 3:
      a=1;
      b=1;
      c=0;
      d=0;
      break;
    case 4:
      a=0;
      b=0;
      c=1;
      d=0;
      break;
    case 5:
      a=1;
      b=0;
      c=1;
      d=0;
      break;
    case 6: 
      a=0;
      b=1;
      c=1;
      d=0;
      break;
    case 7:
      a=1;
      b=1;
      c=1;
      d=0;
      break;
    case 8:
      a=0;
      b=0;
      c=0;
      d=1;
      break;
    case 9:
      a=1;
      b=0;
      c=0;
      d=1;
      break;
    default:
      a=1;
      b=1;
      c=1;
      d=1;
      break;
  }  
  
  // Write to output pins.
  digitalWrite(ledPin_0_d, d);
  digitalWrite(ledPin_0_c, c);
  digitalWrite(ledPin_0_b, b);
  digitalWrite(ledPin_0_a, a);

  // Load the a,b,c,d.. to send to the SN74141 IC (2)
  switch( num2 )
  {
    case 0:
      a=0;
      b=0;
      c=0;
      d=0;
      break;
    case 1:
      a=1;
      b=0;
      c=0;
      d=0;
      break;
    case 2:
      a=0;
      b=1;
      c=0;
      d=0;
      break;
    case 3:
      a=1;
      b=1;
      c=0;
      d=0;
      break;
    case 4:
      a=0;
      b=0;
      c=1;
      d=0;
      break;
    case 5:
      a=1;
      b=0;
      c=1;
      d=0;
      break;
    case 6:
      a=0;
      b=1;
      c=1;
      d=0;
      break;
    case 7:
      a=1;
      b=1;
      c=1;
      d=0;
      break;
    case 8:
      a=0;
      b=0;
      c=0;
      d=1;
      break;
    case 9:
      a=1;
      b=0;
      c=0;
      d=1;
      break;
    default:
      a=1;
      b=1;
      c=1;
      d=1;
      break;
  }
  
  // Write to output pins
  digitalWrite(ledPin_1_d, d);
  digitalWrite(ledPin_1_c, c);
  digitalWrite(ledPin_1_b, b);
  digitalWrite(ledPin_1_a, a);
  
}

getTime.ino

// Time
void isTime(){

  // Get milliseconds.
  runTime = millis();
  //int ssTime = millis();
  
  int hourInput = digitalRead(iVirtual14);  
  int minInput  = digitalRead(iVirtual15);

  if( hourInput == 0 )
    HourButtonPressed = true;
  if( minInput == 0 )
    MinButtonPressed = true;
  if( HourButtonPressed == true && hourInput == 1 )
  {
    clockHourSet++;
    HourButtonPressed = false;
  }
  if( MinButtonPressed == true && minInput == 1 )
  {
    clockMinSet++;
    MinButtonPressed = false;
  }

  // Get time in seconds.
  // Change this value to speed up or
  // slow down the clock, set to smaller number such as 10, 1, or 100 for debugging
  long time = (runTime) / 1000;
  int sstime = (runTime) / 10;
  // Set time based on offset..
  // long hbump = 60*60*clockHourSet;
  //long sbump = 60*60*60*clockHourSet; //change hourset to secondset
  long hbump = 60*60*clockHourSet;
  long mbump = 60*clockMinSet;
  time += mbump + hbump;

  // Convert time to days,hours,mins,seconds
  long days  = time / DAYS;    time -= days  * DAYS; 
  long hours = time / HOURS;   time -= hours * HOURS; 
  long minutes  = time / MINS;    time -= minutes  * MINS; 
  long seconds  = time;      
//  long sseconds  = 76;// time -= seconds  * SECS;
  long sseconds  = runTime / SECS; time -= sseconds  * SECS; 

  // Get the high and low order values for hours,min,seconds. 
  int lowerHours = hours % 10;
  int upperHours = hours - lowerHours;
  int lowerMins = minutes % 10;
  int upperMins = minutes - lowerMins;
  int lowerSeconds = seconds % 10;
  int upperSeconds = seconds - lowerSeconds;
  int lowerSSeconds = sseconds % 10;
  //- lowerSSeconds;
  int upperSSeconds = lowerSSeconds % 10; upperSSeconds = upperSSeconds /10;
  
  if( upperSSeconds >= 10 )  upperSSeconds = upperSSeconds / 10;
  if( upperSeconds >= 10 )   upperSeconds = upperSeconds / 10;
  if( upperMins >= 10 )      upperMins = upperMins / 10;
  if( upperHours >= 10 )     upperHours = upperHours / 10;
 
  if( upperHours == 0 && lowerHours == 0 )
  {
    upperHours = 1;
    lowerHours = 2;
  }
  
  // Fill in the Number array used to display on the tubes.
  
  NumberArray[7] = upperHours;
  NumberArray[6] = lowerHours;
  NumberArray[5] = upperMins;
  NumberArray[4] = lowerMins;
  NumberArray[3] = upperSeconds;  
  NumberArray[2] = lowerSeconds;
  NumberArray[1] = lowerSSeconds; //upperSSeconds;  
  NumberArray[0] = lowerSSeconds; //lowerSSeconds;
  
  Serial.print(lowerSSeconds);
  Serial.println();
  // Display.
  //DisplayFadeNumberString();
  // Display.
  DisplayFadeNumberString();
  
}

setup.ino

// Setup
void setup() {

  // isSetupSN74141
  isSetupSN74141();

  // Open serial communications
 Serial.begin(9600);

}

——

People can contact us: https://www.donluc.com/?page_id=1927

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
  • IoT
  • Robotics
  • Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
  • Unmanned Vehicles Terrestrial and Marine
  • Research & Development (R & D)

Instructor and E-Mentor

  • IoT
  • PIC Microcontrollers
  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics

Follow Us

J. Luc Paquin – Curriculum Vitae – 2022 English & Español
https://www.jlpconsultants.com/luc/

Web: https://www.donluc.com/
Web: https://www.jlpconsultants.com/
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/

Don Luc

Project #22: Synthesizer – Gain – Mk14

——

#DonLucElectronics #DonLuc #Synthesizer #Mozzi #Keyboard #ADSREnvelope #Arduino #SparkFunRedBoard #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant

——

Gain

——

Gain

——

Gain

——

Gain

Gain is the process of managing the relative levels in each step of an audio signal flow to prevent introduction of noise and distortion, particularly in the analogue realm. Ideal gain occurs when each component in an audio signal flow is receiving and transmitting signal in the optimum region of its dynamic range.

Before we can effectively compare these two properties of audio, we need to make sure we understand what each is separately. Keep in mind that both modulate the amplitude of a signal, which translates into a change in loudness. It gets more complicated, dealing with voltage and current in electronics. Amplitude is measured in voltage, which is a direct corollary to volume. In plain language, gain is kind of like an amplitude knob at the input of a piece of hardware or software that controls the loudness before it goes through the circuitry.

DL2208Mk07

1 x SparkFun RedBoard
1 x 10k Ohm Rotary Potentiometer
1 x Potentiometer Knob – Blue
7 x Momentary Button – Panel Mount (Blue)
5 x Momentary Button – Panel Mount (Black)
12 x 10K Ohm Resistor
5 x 10k Ohm Slide Linear Taper Pot – X-Large
5 x Slide Potentiometer Knob – X-Large
1 x Perfboard 13.5 cm x 11 cm
1 x SparkFun Solderable Breadboard
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x SparkFun ProtoShield
1 x Insignia Speakers
1 x SparkFun Cerberus USB Cable

SparkFun RedBoard

LP0 – Analog A0 – Blue
LP1 – Analog A1 – Green
LP2 – Analog A2 – Grey
LP3 – Analog A3 – Yellow
LP4 – Analog A4 – Purple
PO5 – Analog A5
KY1 – 1
KY2 – 2
KY3 – 3
KY4 – 4
KY5 – 5
KY6 – 6
KY7 – 7
KY8 – 8
SPK – 9
KY10 – 10
KY11 – 11
KY12 – 12
KY13 – 13
VIN – +5V
GND – GND

——

DL2208Mk07p.ino

/* ***** Don Luc Electronics © *****
Software Version Information
Project #22: Synthesizer - Gain - Mk14
22-14
DL2208Mk07p.ino
1 x SparkFun RedBoard
1 x 10k Ohm Rotary Potentiometer
1 x Potentiometer Knob - Blue
7 x Momentary Button - Panel Mount (Blue)
5 x Momentary Button - Panel Mount (Black)
12 x 1K Ohm Resistor
5 x 10k Ohm Slide Linear Taper Pot - X-Large
5 x Slide Potentiometer Knob - X-Large
1 x Perfboard 13.5 cm x 11 cm
1 x SparkFun Solderable Breadboard
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x SparkFun ProtoShield
1 x Insignia Speakers
1 x SparkFun Cerberus USB Cable
*/

// Include the Library Code
// Pitches
#include "pitches.h"
// Mozzi
#include <MozziGuts.h>
// Oscillator
#include <Oscil.h>
// Sine Wave Table For Oscillator
#include <tables/sin2048_int8.h>
// Cosine Wave Table For Oscillator
#include <tables/cos2048_int8.h>
// Sawtooth Wave Table For Oscillator
#include <tables/saw2048_int8.h>
// Triangle Wave Table For Oscillator
#include <tables/triangle2048_int8.h>
// Square Wave Table For Oscillator
#include <tables/square_no_alias_2048_int8.h>
// ADSR envelope generator
#include <ADSR.h>

// Simple Keyboard
// Minimum reading of the button that generates a note
const int iKeyboard1 = 1;
const int iKeyboard2 = 2;
const int iKeyboard3 = 3;
const int iKeyboard4 = 4;
const int iKeyboard5 = 5;
const int iKeyboard6 = 6;
const int iKeyboard7 = 7;
const int iKeyboard8 = 8;
const int iKeyboard10 = 10;
const int iKeyboard11 = 11;
const int iKeyboard12 = 12;
const int iKeyboard13 = 13;
// Button is pressed
int iB1 = 1;
int iB2 = 1;
int iB3 = 1;
int iB4 = 1;
int iB5 = 1;
int iB6 = 1;
int iB7 = 1;
int iB8 = 1;
int iB10 = 1;
int iB11 = 1;
int iB12 = 1;
int iB13 = 1;

// Set the input for the potentiometer for Frequency to analog pin 2
const int potFreq = A2;
int iFreg = 1;
int iNoteA = 0;
int iNoteAS = 0;
int iNoteB = 0;
int iNoteC = 0;
int iNoteCS = 0;
int iNoteD = 0;
int iNoteDS = 0;
int iNoteE = 0;
int iNoteF = 0;
int iNoteFS = 0;
int iNoteG = 0;
int iNoteGS = 0;

// Gain
const int iGainPot4 = A4;
// Control variable, use the smallest data size you can for anything used in audio
byte gain = 0;
int iGain = 0;

//Oscillator Functions declared for output envelope 1
// Carrier
Oscil<COS2048_NUM_CELLS, AUDIO_RATE> aCarrier;
// Set the input for the potentiometer for Oscillator to analog pin 4
const int potWave = A5;
// Wave
int iWave;
int iWaveLevel;

// ADSR declaration/definition
// Comment out to use control rate of 128
#define CONTROL_RATE 128
ADSR <CONTROL_RATE, CONTROL_RATE> envelope1;

// Set the input for the potentiometer Attack to analog pin 1
const int potAttack = A0;
// Attack
int attack_level = 0;
int iAttack = 0;

// Set the input for the potentiometer for Decay to analog pin 2
const int potDecay = A1;
// Decay
int decay_level = 0;
int iDecay = 0;

// Set the input for the potentiometer Attack Time to analog pin 3
const int potAttackTime = A3;
// Attack Time
int AttackTime_level = 0;
int iAttackTime = 0;

// Software Version Information
String sver = "22-14";

void loop() {

  // Audio Hook
  audioHook();
  
}

getKeyboard.ino

// getKeyboard
// setupKeyboard
void setupKeyboard() {

  // Initialize the button pin as an input
  pinMode(iKeyboard1, INPUT_PULLUP);
  pinMode(iKeyboard2, INPUT_PULLUP);
  pinMode(iKeyboard3, INPUT_PULLUP);
  pinMode(iKeyboard4, INPUT_PULLUP);
  pinMode(iKeyboard5, INPUT_PULLUP);
  pinMode(iKeyboard6, INPUT_PULLUP);
  pinMode(iKeyboard7, INPUT_PULLUP);
  pinMode(iKeyboard8, INPUT_PULLUP);
  pinMode(iKeyboard10, INPUT_PULLUP);
  pinMode(iKeyboard11, INPUT_PULLUP);
  pinMode(iKeyboard12, INPUT_PULLUP);
  pinMode(iKeyboard13, INPUT_PULLUP);
 
}
// isKeyboard
void isKeyboard() {

  // Oscillators
  isOscil();
  // Choose envelope levels
  // attack_level
  iAttack = mozziAnalogRead( potAttack );
  attack_level = map( iAttack, 0, 1023, 100, 400);
  // Attack Level
  envelope1.setAttackLevel( attack_level );
  // decay_level
  iDecay = mozziAnalogRead( potDecay );
  decay_level = map( iDecay, 0, 1023, 50, 255);
  // Decay Level
  envelope1.setDecayLevel( decay_level );
  // AttackTime_level
  iAttackTime = mozziAnalogRead( potAttackTime );
  AttackTime_level = map( iAttackTime, 0, 1023, 0, 900);
  // Attack Time Level
  envelope1.setAttackTime( AttackTime_level );

  // Read the state of the button value 1
  if ( digitalRead(iKeyboard1) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 1
    iB1 = iB1 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aCarrier.setFreq(iNoteA);

  }
  else
  {
    
    iB1 = iB1 - 1;

  }

  // Read the state of the button value 2
  if ( digitalRead(iKeyboard2) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 2
    iB2 = iB2 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aCarrier.setFreq(iNoteAS);

  }
  else
  {
    
    iB2 = iB2 - 1;
 
  }

  // Read the state of the button value 3
  if ( digitalRead(iKeyboard3) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 3
    iB3 = iB3 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aCarrier.setFreq(iNoteB);

  }
  else
  {
    
    iB3 = iB3 - 1;
 
  }

  // Read the state of the button value 4
  if ( digitalRead(iKeyboard4) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 4
    iB4 = iB4 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aCarrier.setFreq(iNoteC);

  }
  else
  {
    
    iB4 = iB4 - 1;
 
  }

  // Read the state of the button value 5
  if ( digitalRead(iKeyboard5) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 5
    iB5 = iB5 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aCarrier.setFreq(iNoteCS);

  }
  else
  {
    
    iB5 = iB5 - 1;
 
  }

  // Read the state of the button value 6
  if ( digitalRead(iKeyboard6) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 6
    iB6 = iB6 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aCarrier.setFreq(iNoteD);

  }
  else
  {
    
    iB6 = iB6 - 1;

  }

  // Read the state of the button value 7
  if ( digitalRead(iKeyboard7) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 7
    iB7 = iB7 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aCarrier.setFreq(iNoteDS);

  }
  else
  {
    
    iB7 = iB7 - 1;
 
  }

  // Read the state of the button value 8
  if ( digitalRead(iKeyboard8) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 8
    iB8 = iB8 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aCarrier.setFreq(iNoteE);

  }
  else
  {
    
    iB8 = iB8 - 1;

  }

  // Read the state of the button value 10
  if ( digitalRead(iKeyboard10) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 10
    iB10 = iB10 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aCarrier.setFreq(iNoteF);

  }
  else
  {
    
    iB10 = iB10 - 1;

  }

  // Read the state of the button value 11
  if ( digitalRead(iKeyboard11) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 11
    iB11 = iB11 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aCarrier.setFreq(iNoteFS);

  }
  else
  {
    
    iB11 = iB11 - 1;
 
  }

  // Read the state of the button value 12
  if ( digitalRead(iKeyboard12) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 12
    iB12 = iB12 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aCarrier.setFreq(iNoteG);

  }
  else
  {
    
    iB12 = iB12 - 1;
    
  }

  // Read the state of the button value 13
  if ( digitalRead(iKeyboard13) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 13
    iB13 = iB13 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aCarrier.setFreq(iNoteGS);

  }
  else
  {
    
    iB13 = iB13 - 1;

  }

}

getMozzi.ino

// Mozzi
// Update Control
void updateControl(){

  // Frequency
  isPitches();
  
  // Keyboard
  isKeyboard();

  // Gain
  // As byte, this will automatically roll around to 255 when it passes 0
  iGain = mozziAnalogRead( iGainPot4 );
  gain = map( iGain, 0, 1023, 0, 255);

}
// Update Audio
int updateAudio()
{

  // Update Audio
  // ADSR declaration/definition
  envelope1.update();
  // >>8 for AUDIO_MODE STANDARD
  return (int) (envelope1.next() * aCarrier.next() * gain)>>8;

}

getOscillators.ino

// Oscillators
// isOscil
void isOscil(){
  
  // Oscillators
  // Value is 0-1023
  iWave = mozziAnalogRead(potWave);
  iWaveLevel = map(iWave, 0, 1023, 1, 5);

  switch (iWaveLevel) {
    case 1:
      // Sine Wave
      aCarrier.setTable(SIN2048_DATA);
      break;
    case 2:
      // Cosine Wave
      aCarrier.setTable(COS2048_DATA);
      break;
    case 3:
      // Sawtooth Wave
      aCarrier.setTable(SAW2048_DATA);
      break;
    case 4:
      // Triangle Wave
      aCarrier.setTable(TRIANGLE2048_DATA);
      break;
    case 5:
      // Square Wave
      aCarrier.setTable(SQUARE_NO_ALIAS_2048_DATA);
      break;
    default: // Case 0
      // Sine Wave
      aCarrier.setTable(SIN2048_DATA);
      break;
  }
  
}

getPitches.ino

// Pitches
// isPitches
void isPitches(){
  
  // Frequency
  // Value is 0-1023
  iFreg = mozziAnalogRead(potFreq);
  iFreg = map(iFreg, 0, 1023, 2, 5);

  // Range Frequency Note Low => High
  switch ( iFreg ) {
    case 1:
      // NOTE A1
      iNoteA = NOTE_A1;
      iNoteAS = NOTE_AS1;
      iNoteB = NOTE_B1;
      iNoteC = NOTE_C2;
      iNoteCS = NOTE_CS2;
      iNoteD = NOTE_D2;
      iNoteDS = NOTE_DS2;
      iNoteE = NOTE_E2;
      iNoteF = NOTE_F2;
      iNoteFS = NOTE_FS2;
      iNoteG = NOTE_G2;
      iNoteGS = NOTE_GS2;
      break;
    case 2:
      // NOTE A2
      iNoteA = NOTE_A2;
      iNoteAS = NOTE_AS2;
      iNoteB = NOTE_B2;
      iNoteC = NOTE_C3;
      iNoteCS = NOTE_CS3;
      iNoteD = NOTE_D3;
      iNoteDS = NOTE_DS3;
      iNoteE = NOTE_E3;
      iNoteF = NOTE_F3;
      iNoteFS = NOTE_FS3;
      iNoteG = NOTE_G3;
      iNoteGS = NOTE_GS3;
      break;
    case 3:
      // NOTE A3
      iNoteA = NOTE_A3;
      iNoteAS = NOTE_AS3;
      iNoteB = NOTE_B3;
      iNoteC = NOTE_C4;
      iNoteD = NOTE_D4;
      iNoteDS = NOTE_DS4;
      iNoteE = NOTE_E4;
      iNoteF = NOTE_F4;
      iNoteFS = NOTE_FS4;
      iNoteG = NOTE_G4;
      iNoteGS = NOTE_GS4;
      break;
    case 4:
      // NOTE A4
      iNoteA = NOTE_A4;
      iNoteAS = NOTE_AS4;
      iNoteB = NOTE_B4;
      iNoteC = NOTE_C5;
      iNoteCS = NOTE_CS5;
      iNoteD = NOTE_D5;
      iNoteE = NOTE_E5;
      iNoteF = NOTE_F5;
      iNoteFS = NOTE_FS5;
      iNoteG = NOTE_G5;
      iNoteGS = NOTE_GS5;
      break;
    case 5:
      // NOTE A5
      iNoteA = NOTE_A5;
      iNoteAS = NOTE_AS5;
      iNoteB = NOTE_B5;
      iNoteC = NOTE_C6;
      iNoteCS = NOTE_CS6;
      iNoteD = NOTE_D6;
      iNoteDS = NOTE_DS6;
      iNoteE = NOTE_E6;
      iNoteF = NOTE_F6;
      iNoteFS = NOTE_FS6;
      iNoteG = NOTE_G6;
      iNoteGS = NOTE_GS6;
      break;
    case 6:
      // NOTE A6
      iNoteA = NOTE_A6;
      iNoteAS = NOTE_AS6;
      iNoteB = NOTE_B6;
      iNoteC = NOTE_C7;
      iNoteCS = NOTE_CS7;
      iNoteD = NOTE_D7;
      iNoteDS = NOTE_DS7;
      iNoteE = NOTE_E7;
      iNoteF = NOTE_F7;
      iNoteFS = NOTE_FS7;
      iNoteG = NOTE_G7;
      iNoteGS = NOTE_GS7;
      break;
  }
  
}

pitches.h

/*****************************************************************
 * Pitches NOTE_B0 <=> NOTE_DS8 - NOTE_A4 is "A" measured at 440Hz
 *****************************************************************/

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1  35
#define NOTE_D1  37
#define NOTE_DS1  39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1  46
#define NOTE_G1  49
#define NOTE_GS1  52
#define NOTE_A1  55
#define NOTE_AS1  58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2  69
#define NOTE_D2  73
#define NOTE_DS2  78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2  93
#define NOTE_G2  98
#define NOTE_GS2  104
#define NOTE_A2  110
#define NOTE_AS2  117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3  139
#define NOTE_D3  147
#define NOTE_DS3  156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3  208
#define NOTE_A3  220
#define NOTE_AS3  233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4  277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4  370
#define NOTE_G4  392
#define NOTE_GS4  415
#define NOTE_A4  440
#define NOTE_AS4  466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5  554
#define NOTE_D5  587
#define NOTE_DS5  622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5  740
#define NOTE_G5  784
#define NOTE_GS5  831
#define NOTE_A5  880
#define NOTE_AS5  932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6  1109
#define NOTE_D6  1175
#define NOTE_DS6  1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6  1480
#define NOTE_G6  1568
#define NOTE_GS6  1661
#define NOTE_A6  1760
#define NOTE_AS6  1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7  2217
#define NOTE_D7  2349
#define NOTE_DS7  2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7  2960
#define NOTE_G7  3136
#define NOTE_GS7  3322
#define NOTE_A7  3520
#define NOTE_AS7  3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8  4435
#define NOTE_D8  4699
#define NOTE_DS8  4978

setup.ino

// Setup
void setup() {

  // Setup Keyboard
  setupKeyboard();

  // Mozzi Start
  startMozzi( CONTROL_RATE );
  // Sets Attack and Decay Levels; assumes Sustain, Decay, and Idle times
  envelope1.setADLevels(200,200);
  // Sets Decay time in milliseconds
  envelope1.setDecayTime(200);
  // Sustain Time setting for envelope1
  envelope1.setSustainTime(52500);

}

——

People can contact us: https://www.donluc.com/?page_id=1927

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
  • IoT
  • Robotics
  • Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
  • Unmanned Vehicles Terrestrial and Marine
  • Research & Development (R & D)

Instructor and E-Mentor

  • IoT
  • PIC Microcontrollers
  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics

Follow Us

J. Luc Paquin – Curriculum Vitae – 2022 English & Español
https://www.jlpconsultants.com/luc/

Web: https://www.donluc.com/
Web: https://www.jlpconsultants.com/
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/

Don Luc

Project #22: Synthesizer – Wave – Mk13

——

DonLucElectronics #DonLuc #Synthesizer #Mozzi #Keyboard #ADSREnvelope #Oscillators #Arduino #SparkFunRedBoard #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant

——

Wave

——

Wave

——

Wave

——

Sine Wave and Cosine Wave

A sine wave is a mathematical curve defined in terms of the sine trigonometric function. It is a type of continuous wave and also a smooth periodic function. It occurs often in mathematics, as well as in physics, engineering, signal processing and many other fields.

The term sinusoid describes any wave with characteristics of a sine wave. Thus, a cosine wave is also said to be sinusoidal, which is also a sine wave with a phase-shift. Because of this head start, it is often said that the cosine function leads the sine function or the sine lags the cosine. The term sinusoidal thereby collectively refers to both sine waves and cosine waves with any phase offset.

Sawtooth Wave

The sawtooth wave is a kind of non-sinusoidal waveform. It is so named based on its resemblance to the teeth of a plain toothed saw with a zero rake angle. A single sawtooth, or an intermittently triggered sawtooth, is called a ramp waveform.

Triangle Wave

A triangle wave is a non-sinusoidal waveform named for its triangular shape. It is a periodic, piecewise linear, continuous real function.

Square Wave

A square wave is a non-sinusoidal periodic waveform in which the amplitude alternates at a steady frequency between fixed minimum and maximum values, with the same duration at minimum and maximum. In an ideal square wave, the transitions between minimum and maximum are instantaneous.

DL2208Mk06

1 x SparkFun RedBoard
1 x 10k Ohm Rotary Potentiometer
1 x Potentiometer Knob – Blue
7 x Momentary Button – Panel Mount (Blue)
5 x Momentary Button – Panel Mount (Black)
12 x 10K Ohm Resistor
5 x 10k Ohm Slide Linear Taper Pot – X-Large
5 x Slide Potentiometer Knob – X-Large
1 x Perfboard 13.5 cm x 11 cm
1 x SparkFun Solderable Breadboard
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x SparkFun ProtoShield
1 x Insignia Speakers
1 x SparkFun Cerberus USB Cable

SparkFun RedBoard

LP0 – Analog A0 – Blue
LP1 – Analog A1 – Green
LP2 – Analog A2 – Grey
LP3 – Analog A3 – Yellow
LP4 – Analog A4 – Purple
PO5 – Analog A5
KY1 – 1
KY2 – 2
KY3 – 3
KY4 – 4
KY5 – 5
KY6 – 6
KY7 – 7
KY8 – 8
SPK – 9
KY10 – 10
KY11 – 11
KY12 – 12
KY13 – 13
VIN – +5V
GND – GND

——

DL2208Mk06p.ino

/* ***** Don Luc Electronics © *****
Software Version Information
Project #22: Synthesizer - Wave - Mk13
22-13
DL2208Mk06p.ino
1 x SparkFun RedBoard
1 x 10k Ohm Rotary Potentiometer
1 x Potentiometer Knob - Blue
7 x Momentary Button - Panel Mount (Blue)
5 x Momentary Button - Panel Mount (Black)
12 x 1K Ohm Resistor
5 x 10k Ohm Slide Linear Taper Pot - X-Large
5 x Slide Potentiometer Knob - X-Large
1 x Perfboard 13.5 cm x 11 cm
1 x SparkFun Solderable Breadboard
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x SparkFun ProtoShield
1 x Insignia Speakers
1 x SparkFun Cerberus USB Cable
*/

// Include the Library Code
// Pitches
#include "pitches.h"
// Mozzi
#include <MozziGuts.h>
// Oscillator
#include <Oscil.h>
// Sine Wave Table For Oscillator
#include <tables/sin2048_int8.h>
// Cosine Wave Table For Oscillator
#include <tables/cos2048_int8.h>
// Sawtooth Wave Table For Oscillator
#include <tables/saw2048_int8.h>
// Triangle Wave Table For Oscillator
#include <tables/triangle2048_int8.h>
// Square Wave Table For Oscillator
#include <tables/square_no_alias_2048_int8.h>
// ADSR envelope generator
#include <ADSR.h>

// Simple Keyboard
// Minimum reading of the button that generates a note
const int iKeyboard1 = 1;
const int iKeyboard2 = 2;
const int iKeyboard3 = 3;
const int iKeyboard4 = 4;
const int iKeyboard5 = 5;
const int iKeyboard6 = 6;
const int iKeyboard7 = 7;
const int iKeyboard8 = 8;
const int iKeyboard10 = 10;
const int iKeyboard11 = 11;
const int iKeyboard12 = 12;
const int iKeyboard13 = 13;
// Button is pressed
int iB1 = 1;
int iB2 = 1;
int iB3 = 1;
int iB4 = 1;
int iB5 = 1;
int iB6 = 1;
int iB7 = 1;
int iB8 = 1;
int iB10 = 1;
int iB11 = 1;
int iB12 = 1;
int iB13 = 1;

// Set the input for the potentiometer for Frequency to analog pin 2
const int potFreq = A2;
int iFreg = 1;
int iNoteA = 0;
int iNoteAS = 0;
int iNoteB = 0;
int iNoteC = 0;
int iNoteCS = 0;
int iNoteD = 0;
int iNoteDS = 0;
int iNoteE = 0;
int iNoteF = 0;
int iNoteFS = 0;
int iNoteG = 0;
int iNoteGS = 0;

// Potentiometer
int iPot4 = A4;

//Oscillator Functions declared for output envelope 1
// Carrier
Oscil<COS2048_NUM_CELLS, AUDIO_RATE> aCarrier;
// Set the input for the potentiometer for Oscillator to analog pin 4
const int potWave = A5;
// Wave
int iWave;
int iWaveLevel;

// ADSR declaration/definition
// Comment out to use control rate of 128
#define CONTROL_RATE 128
ADSR <CONTROL_RATE, CONTROL_RATE> envelope1;

// Set the input for the potentiometer Attack to analog pin 1
const int potAttack = A0;
// Attack
int attack_level = 0;
int iAttack = 0;

// Set the input for the potentiometer for Decay to analog pin 2
const int potDecay = A1;
// Decay
int decay_level = 0;
int iDecay = 0;

// Set the input for the potentiometer Attack Time to analog pin 3
const int potAttackTime = A3;
// Attack Time
int AttackTime_level = 0;
int iAttackTime = 0;

// Software Version Information
String sver = "22-13";

void loop() {

  // Audio Hook
  audioHook();
  
}

getKeyboard.ino

// getKeyboard
// setupKeyboard
void setupKeyboard() {

  // Initialize the button pin as an input
  pinMode(iKeyboard1, INPUT_PULLUP);
  pinMode(iKeyboard2, INPUT_PULLUP);
  pinMode(iKeyboard3, INPUT_PULLUP);
  pinMode(iKeyboard4, INPUT_PULLUP);
  pinMode(iKeyboard5, INPUT_PULLUP);
  pinMode(iKeyboard6, INPUT_PULLUP);
  pinMode(iKeyboard7, INPUT_PULLUP);
  pinMode(iKeyboard8, INPUT_PULLUP);
  pinMode(iKeyboard10, INPUT_PULLUP);
  pinMode(iKeyboard11, INPUT_PULLUP);
  pinMode(iKeyboard12, INPUT_PULLUP);
  pinMode(iKeyboard13, INPUT_PULLUP);
 
}
// isKeyboard
void isKeyboard() {

  // Oscillators
  isOscil();
  // Choose envelope levels
  // attack_level
  iAttack = mozziAnalogRead( potAttack );
  attack_level = map( iAttack, 0, 1023, 100, 400);
  // Attack Level
  envelope1.setAttackLevel( attack_level );
  // decay_level
  iDecay = mozziAnalogRead( potDecay );
  decay_level = map( iDecay, 0, 1023, 50, 255);
  // Decay Level
  envelope1.setDecayLevel( decay_level );
  // AttackTime_level
  iAttackTime = mozziAnalogRead( potAttackTime );
  AttackTime_level = map( iAttackTime, 0, 1023, 0, 900);
  // Attack Time Level
  envelope1.setAttackTime( AttackTime_level );

  // Read the state of the button value 1
  if ( digitalRead(iKeyboard1) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 1
    iB1 = iB1 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aCarrier.setFreq(iNoteA);

  }
  else
  {
    
    iB1 = iB1 - 1;

  }

  // Read the state of the button value 2
  if ( digitalRead(iKeyboard2) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 2
    iB2 = iB2 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aCarrier.setFreq(iNoteAS);

  }
  else
  {
    
    iB2 = iB2 - 1;
 
  }

  // Read the state of the button value 3
  if ( digitalRead(iKeyboard3) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 3
    iB3 = iB3 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aCarrier.setFreq(iNoteB);

  }
  else
  {
    
    iB3 = iB3 - 1;
 
  }

  // Read the state of the button value 4
  if ( digitalRead(iKeyboard4) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 4
    iB4 = iB4 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aCarrier.setFreq(iNoteC);

  }
  else
  {
    
    iB4 = iB4 - 1;
 
  }

  // Read the state of the button value 5
  if ( digitalRead(iKeyboard5) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 5
    iB5 = iB5 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aCarrier.setFreq(iNoteCS);

  }
  else
  {
    
    iB5 = iB5 - 1;
 
  }

  // Read the state of the button value 6
  if ( digitalRead(iKeyboard6) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 6
    iB6 = iB6 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aCarrier.setFreq(iNoteD);

  }
  else
  {
    
    iB6 = iB6 - 1;

  }

  // Read the state of the button value 7
  if ( digitalRead(iKeyboard7) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 7
    iB7 = iB7 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aCarrier.setFreq(iNoteDS);

  }
  else
  {
    
    iB7 = iB7 - 1;
 
  }

  // Read the state of the button value 8
  if ( digitalRead(iKeyboard8) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 8
    iB8 = iB8 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aCarrier.setFreq(iNoteE);

  }
  else
  {
    
    iB8 = iB8 - 1;

  }

  // Read the state of the button value 10
  if ( digitalRead(iKeyboard10) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 10
    iB10 = iB10 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aCarrier.setFreq(iNoteF);

  }
  else
  {
    
    iB10 = iB10 - 1;

  }

  // Read the state of the button value 11
  if ( digitalRead(iKeyboard11) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 11
    iB11 = iB11 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aCarrier.setFreq(iNoteFS);

  }
  else
  {
    
    iB11 = iB11 - 1;
 
  }

  // Read the state of the button value 12
  if ( digitalRead(iKeyboard12) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 12
    iB12 = iB12 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aCarrier.setFreq(iNoteG);

  }
  else
  {
    
    iB12 = iB12 - 1;
    
  }

  // Read the state of the button value 13
  if ( digitalRead(iKeyboard13) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 13
    iB13 = iB13 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aCarrier.setFreq(iNoteGS);

  }
  else
  {
    
    iB13 = iB13 - 1;

  }

}

getMozzi.ino

// Mozzi
// Update Control
void updateControl(){

  // Frequency
  isPitches();
  
  // Keyboard
  isKeyboard();

}
// Update Audio
int updateAudio()
{

  // Update Audio
  // ADSR declaration/definition
  envelope1.update();
  // >>8 for AUDIO_MODE STANDARD
  return (int) (envelope1.next() * aCarrier.next())>>8;

}

getOscillators.ino

// Oscillators
// isOscil
void isOscil(){
  
  // Oscillators
  // Value is 0-1023
  iWave = mozziAnalogRead(potWave);
  iWaveLevel = map(iWave, 0, 1023, 1, 5);

  switch (iWaveLevel) {
    case 1:
      // Sine Wave
      aCarrier.setTable(SIN2048_DATA);
      break;
    case 2:
      // Cosine Wave
      aCarrier.setTable(COS2048_DATA);
      break;
    case 3:
      // Sawtooth Wave
      aCarrier.setTable(SAW2048_DATA);
      break;
    case 4:
      // Triangle Wave
      aCarrier.setTable(TRIANGLE2048_DATA);
      break;
    case 5:
      // Square Wave
      aCarrier.setTable(SQUARE_NO_ALIAS_2048_DATA);
      break;
    default: // Case 0
      // Sine Wave
      aCarrier.setTable(SIN2048_DATA);
      break;
  }
  
}

getPitches.ino

// Pitches
// isPitches
void isPitches(){
  
  // Frequency
  // Value is 0-1023
  iFreg = mozziAnalogRead(potFreq);
  iFreg = map(iFreg, 0, 1023, 2, 6);

  // Range Frequency Note Low => High
  switch ( iFreg ) {
    case 1:
      // NOTE A1
      iNoteA = NOTE_A1;
      iNoteAS = NOTE_AS1;
      iNoteB = NOTE_B1;
      iNoteC = NOTE_C2;
      iNoteCS = NOTE_CS2;
      iNoteD = NOTE_D2;
      iNoteDS = NOTE_DS2;
      iNoteE = NOTE_E2;
      iNoteF = NOTE_F2;
      iNoteFS = NOTE_FS2;
      iNoteG = NOTE_G2;
      iNoteGS = NOTE_GS2;
      break;
    case 2:
      // NOTE A2
      iNoteA = NOTE_A2;
      iNoteAS = NOTE_AS2;
      iNoteB = NOTE_B2;
      iNoteC = NOTE_C3;
      iNoteCS = NOTE_CS3;
      iNoteD = NOTE_D3;
      iNoteDS = NOTE_DS3;
      iNoteE = NOTE_E3;
      iNoteF = NOTE_F3;
      iNoteFS = NOTE_FS3;
      iNoteG = NOTE_G3;
      iNoteGS = NOTE_GS3;
      break;
    case 3:
      // NOTE A3
      iNoteA = NOTE_A3;
      iNoteAS = NOTE_AS3;
      iNoteB = NOTE_B3;
      iNoteC = NOTE_C4;
      iNoteD = NOTE_D4;
      iNoteDS = NOTE_DS4;
      iNoteE = NOTE_E4;
      iNoteF = NOTE_F4;
      iNoteFS = NOTE_FS4;
      iNoteG = NOTE_G4;
      iNoteGS = NOTE_GS4;
      break;
    case 4:
      // NOTE A4
      iNoteA = NOTE_A4;
      iNoteAS = NOTE_AS4;
      iNoteB = NOTE_B4;
      iNoteC = NOTE_C5;
      iNoteCS = NOTE_CS5;
      iNoteD = NOTE_D5;
      iNoteE = NOTE_E5;
      iNoteF = NOTE_F5;
      iNoteFS = NOTE_FS5;
      iNoteG = NOTE_G5;
      iNoteGS = NOTE_GS5;
      break;
    case 5:
      // NOTE A5
      iNoteA = NOTE_A5;
      iNoteAS = NOTE_AS5;
      iNoteB = NOTE_B5;
      iNoteC = NOTE_C6;
      iNoteCS = NOTE_CS6;
      iNoteD = NOTE_D6;
      iNoteDS = NOTE_DS6;
      iNoteE = NOTE_E6;
      iNoteF = NOTE_F6;
      iNoteFS = NOTE_FS6;
      iNoteG = NOTE_G6;
      iNoteGS = NOTE_GS6;
      break;
    case 6:
      // NOTE A6
      iNoteA = NOTE_A6;
      iNoteAS = NOTE_AS6;
      iNoteB = NOTE_B6;
      iNoteC = NOTE_C7;
      iNoteCS = NOTE_CS7;
      iNoteD = NOTE_D7;
      iNoteDS = NOTE_DS7;
      iNoteE = NOTE_E7;
      iNoteF = NOTE_F7;
      iNoteFS = NOTE_FS7;
      iNoteG = NOTE_G7;
      iNoteGS = NOTE_GS7;
      break;
  }
  
}

pitches.h

/*****************************************************************
 * Pitches NOTE_B0 <=> NOTE_DS8 - NOTE_A4 is "A" measured at 440Hz
 *****************************************************************/

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1  35
#define NOTE_D1  37
#define NOTE_DS1  39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1  46
#define NOTE_G1  49
#define NOTE_GS1  52
#define NOTE_A1  55
#define NOTE_AS1  58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2  69
#define NOTE_D2  73
#define NOTE_DS2  78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2  93
#define NOTE_G2  98
#define NOTE_GS2  104
#define NOTE_A2  110
#define NOTE_AS2  117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3  139
#define NOTE_D3  147
#define NOTE_DS3  156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3  208
#define NOTE_A3  220
#define NOTE_AS3  233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4  277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4  370
#define NOTE_G4  392
#define NOTE_GS4  415
#define NOTE_A4  440
#define NOTE_AS4  466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5  554
#define NOTE_D5  587
#define NOTE_DS5  622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5  740
#define NOTE_G5  784
#define NOTE_GS5  831
#define NOTE_A5  880
#define NOTE_AS5  932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6  1109
#define NOTE_D6  1175
#define NOTE_DS6  1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6  1480
#define NOTE_G6  1568
#define NOTE_GS6  1661
#define NOTE_A6  1760
#define NOTE_AS6  1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7  2217
#define NOTE_D7  2349
#define NOTE_DS7  2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7  2960
#define NOTE_G7  3136
#define NOTE_GS7  3322
#define NOTE_A7  3520
#define NOTE_AS7  3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8  4435
#define NOTE_D8  4699
#define NOTE_DS8  4978

setup.ino

// Setup
void setup() {

  // Setup Keyboard
  setupKeyboard();

  // Mozzi Start
  startMozzi( CONTROL_RATE );
  // Sets Attack and Decay Levels; assumes Sustain, Decay, and Idle times
  envelope1.setADLevels(200,200);
  // Sets Decay time in milliseconds
  envelope1.setDecayTime(200);
  // Sustain Time setting for envelope1
  envelope1.setSustainTime(52500);

}

——

People can contact us: https://www.donluc.com/?page_id=1927

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
  • IoT
  • Robotics
  • Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
  • Unmanned Vehicles Terrestrial and Marine
  • Research & Development (R & D)

Instructor and E-Mentor

  • IoT
  • PIC Microcontrollers
  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics

Follow Us

J. Luc Paquin – Curriculum Vitae – 2022 English & Español
https://www.jlpconsultants.com/luc/

Web: https://www.donluc.com/
Web: https://www.jlpconsultants.com/
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/

Don Luc

Project #22: Synthesizer – Attack Time Level – Mk12

——

#DonLucElectronics #DonLuc #Synthesizer #Mozzi #Keyboard #ADSREnvelope #Arduino #SparkFunRedBoard #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant

——

Attack Time Level

——

Attack Time Level

——

Attack Time Level

——

Attack Time Level

When creating artificial waveforms in a synthesizer, changes in the signal amplitude over time are controlled by an envelope generator which typically has controls to adjust the Attack, Decay, Sustain and Release times, triggered by the pressing and subsequent release of a key on the keyboard. The Attack Time Level determines the time taken for the signal to grow to its maximum amplitude, initiated by the pressing of a key. By lengthening the attack and release times, you can create rich, lush tones. By shortening the time of the attack and release phases, you can create percussive, staccato sounds.

DL2208Mk05

1 x SparkFun RedBoard
7 x Momentary Button – Panel Mount (Blue)
5 x Momentary Button – Panel Mount (Black)
12 x 10K Ohm Resistor
5 x 10k Ohm Slide Linear Taper Pot – X-Large
5 x Slide Potentiometer Knob – X-Large
1 x Perfboard 13.5 cm x 11 cm
1 x SparkFun Solderable Breadboard
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x SparkFun ProtoShield
1 x Insignia Speakers
1 x SparkFun Cerberus USB Cable

SparkFun RedBoard

LP0 – Analog A0 – Blue
LP1 – Analog A1 – Green
LP2 – Analog A2 – Grey
LP3 – Analog A3 – Yellow
LP4 – Analog A4 – Purple
KY1 – 1
KY2 – 2
KY3 – 3
KY4 – 4
KY5 – 5
KY6 – 6
KY7 – 7
KY8 – 8
SPK – 9
KY10 – 10
KY11 – 11
KY12 – 12
KY13 – 13
VIN – +5V
GND – GND

——

DL2208Mk05p.ino

/* ***** Don Luc Electronics © *****
Software Version Information
Project #22: Synthesizer - Attack Time Level - Mk12
22-12
DL2208Mk05p.ino
1 x SparkFun RedBoard
7 x Momentary Button - Panel Mount (Blue)
5 x Momentary Button - Panel Mount (Black)
12 x 1K Ohm Resistor
5 x 10k Ohm Slide Linear Taper Pot - X-Large
5 x Slide Potentiometer Knob - X-Large
1 x Perfboard 13.5 cm x 11 cm
1 x SparkFun Solderable Breadboard
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x SparkFun ProtoShield
1 x Insignia Speakers
1 x SparkFun Cerberus USB Cable
*/

// Include the Library Code
// Pitches
#include "pitches.h"
// Mozzi
#include <MozziGuts.h>
// Oscillator
#include <Oscil.h>
// Sine Wave Table For Oscillator
#include <tables/sin2048_int8.h>
// ADSR envelope generator
#include <ADSR.h>

// Simple Keyboard
// Minimum reading of the button that generates a note
const int iKeyboard1 = 1;
const int iKeyboard2 = 2;
const int iKeyboard3 = 3;
const int iKeyboard4 = 4;
const int iKeyboard5 = 5;
const int iKeyboard6 = 6;
const int iKeyboard7 = 7;
const int iKeyboard8 = 8;
const int iKeyboard10 = 10;
const int iKeyboard11 = 11;
const int iKeyboard12 = 12;
const int iKeyboard13 = 13;
// Button is pressed
int iB1 = 1;
int iB2 = 1;
int iB3 = 1;
int iB4 = 1;
int iB5 = 1;
int iB6 = 1;
int iB7 = 1;
int iB8 = 1;
int iB10 = 1;
int iB11 = 1;
int iB12 = 1;
int iB13 = 1;

// Set the input for the potentiometer for Frequency to analog pin 2
const int potFreq = A2;
int iFreg = 1;
int iNoteA = 0;
int iNoteAS = 0;
int iNoteB = 0;
int iNoteC = 0;
int iNoteCS = 0;
int iNoteD = 0;
int iNoteDS = 0;
int iNoteE = 0;
int iNoteF = 0;
int iNoteFS = 0;
int iNoteG = 0;
int iNoteGS = 0;

// Potentiometer
int iPot4 = A4;

//Oscillator Functions declared for output envelope 1 
// Sine Wave
Oscil <2048, AUDIO_RATE> aSin1(SIN2048_DATA);

// ADSR declaration/definition
// Comment out to use control rate of 128
#define CONTROL_RATE 128
ADSR <CONTROL_RATE, CONTROL_RATE> envelope1;

// Set the input for the potentiometer Attack to analog pin 1
const int potAttack = A0;
// Attack
int attack_level = 0;
int iAttack = 0;

// Set the input for the potentiometer for Decay to analog pin 2
const int potDecay = A1;
// Decay
int decay_level = 0;
int iDecay = 0;

// Set the input for the potentiometer Attack Time to analog pin 3
const int potAttackTime = A3;
// Attack Time
int AttackTime_level = 0;
int iAttackTime = 0;

// Software Version Information
String sver = "22-12";

void loop() {

  // Audio Hook
  audioHook();
  
}

getKeyboard.ino

// getKeyboard
// setupKeyboard
void setupKeyboard() {

  // Initialize the button pin as an input
  pinMode(iKeyboard1, INPUT_PULLUP);
  pinMode(iKeyboard2, INPUT_PULLUP);
  pinMode(iKeyboard3, INPUT_PULLUP);
  pinMode(iKeyboard4, INPUT_PULLUP);
  pinMode(iKeyboard5, INPUT_PULLUP);
  pinMode(iKeyboard6, INPUT_PULLUP);
  pinMode(iKeyboard7, INPUT_PULLUP);
  pinMode(iKeyboard8, INPUT_PULLUP);
  pinMode(iKeyboard10, INPUT_PULLUP);
  pinMode(iKeyboard11, INPUT_PULLUP);
  pinMode(iKeyboard12, INPUT_PULLUP);
  pinMode(iKeyboard13, INPUT_PULLUP);
 
}
// isKeyboard
void isKeyboard() {

  // Choose envelope levels
  // attack_level
  iAttack = mozziAnalogRead( potAttack );
  attack_level = map( iAttack, 0, 1023, 100, 400);
  // Attack Level
  envelope1.setAttackLevel( attack_level );
  // decay_level
  iDecay = mozziAnalogRead( potDecay );
  decay_level = map( iDecay, 0, 1023, 50, 255);
  // Decay Level
  envelope1.setDecayLevel( decay_level );
  // AttackTime_level
  iAttackTime = mozziAnalogRead( potAttackTime );
  AttackTime_level = map( iAttackTime, 0, 1023, 0, 900);
  // Attack Time Level
  envelope1.setAttackTime( AttackTime_level );

  // Read the state of the button value 1
  if ( digitalRead(iKeyboard1) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 1
    iB1 = iB1 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteA);

  }
  else
  {
    
    iB1 = iB1 - 1;

  }

  // Read the state of the button value 2
  if ( digitalRead(iKeyboard2) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 2
    iB2 = iB2 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteAS);

  }
  else
  {
    
    iB2 = iB2 - 1;
 
  }

  // Read the state of the button value 3
  if ( digitalRead(iKeyboard3) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 3
    iB3 = iB3 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteB);

  }
  else
  {
    
    iB3 = iB3 - 1;
 
  }

  // Read the state of the button value 4
  if ( digitalRead(iKeyboard4) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 4
    iB4 = iB4 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteC);

  }
  else
  {
    
    iB4 = iB4 - 1;
 
  }

  // Read the state of the button value 5
  if ( digitalRead(iKeyboard5) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 5
    iB5 = iB5 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteCS);

  }
  else
  {
    
    iB5 = iB5 - 1;
 
  }

  // Read the state of the button value 6
  if ( digitalRead(iKeyboard6) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 6
    iB6 = iB6 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteD);

  }
  else
  {
    
    iB6 = iB6 - 1;

  }

  // Read the state of the button value 7
  if ( digitalRead(iKeyboard7) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 7
    iB7 = iB7 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteDS);

  }
  else
  {
    
    iB7 = iB7 - 1;
 
  }

  // Read the state of the button value 8
  if ( digitalRead(iKeyboard8) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 8
    iB8 = iB8 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteE);

  }
  else
  {
    
    iB8 = iB8 - 1;

  }

  // Read the state of the button value 10
  if ( digitalRead(iKeyboard10) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 10
    iB10 = iB10 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteF);

  }
  else
  {
    
    iB10 = iB10 - 1;

  }

  // Read the state of the button value 11
  if ( digitalRead(iKeyboard11) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 11
    iB11 = iB11 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteFS);

  }
  else
  {
    
    iB11 = iB11 - 1;
 
  }

  // Read the state of the button value 12
  if ( digitalRead(iKeyboard12) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 12
    iB12 = iB12 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteG);

  }
  else
  {
    
    iB12 = iB12 - 1;
    
  }

  // Read the state of the button value 13
  if ( digitalRead(iKeyboard13) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 13
    iB13 = iB13 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteGS);

  }
  else
  {
    
    iB13 = iB13 - 1;

  }

}

getMozzi.ino

// Mozzi
// Update Control
void updateControl(){

  // Frequency
  isPitches();
  
  // Keyboard
  isKeyboard();

}
// Update Audio
int updateAudio()
{

  // Update Audio
  // ADSR declaration/definition
  envelope1.update();
  // >>8 for AUDIO_MODE STANDARD
  return (int) (envelope1.next() * aSin1.next())>>8;

}

getPitches.ino

// Pitches
// isPitches
void isPitches(){
  
  // Frequency
  // Value is 0-1023
  iFreg = mozziAnalogRead(potFreq);
  iFreg = map(iFreg, 0, 1023, 2, 6);

  // Range Frequency Note Low => High
  switch ( iFreg ) {
    case 1:
      // NOTE A1
      iNoteA = NOTE_A1;
      iNoteAS = NOTE_AS1;
      iNoteB = NOTE_B1;
      iNoteC = NOTE_C2;
      iNoteCS = NOTE_CS2;
      iNoteD = NOTE_D2;
      iNoteDS = NOTE_DS2;
      iNoteE = NOTE_E2;
      iNoteF = NOTE_F2;
      iNoteFS = NOTE_FS2;
      iNoteG = NOTE_G2;
      iNoteGS = NOTE_GS2;
      break;
    case 2:
      // NOTE A2
      iNoteA = NOTE_A2;
      iNoteAS = NOTE_AS2;
      iNoteB = NOTE_B2;
      iNoteC = NOTE_C3;
      iNoteCS = NOTE_CS3;
      iNoteD = NOTE_D3;
      iNoteDS = NOTE_DS3;
      iNoteE = NOTE_E3;
      iNoteF = NOTE_F3;
      iNoteFS = NOTE_FS3;
      iNoteG = NOTE_G3;
      iNoteGS = NOTE_GS3;
      break;
    case 3:
      // NOTE A3
      iNoteA = NOTE_A3;
      iNoteAS = NOTE_AS3;
      iNoteB = NOTE_B3;
      iNoteC = NOTE_C4;
      iNoteD = NOTE_D4;
      iNoteDS = NOTE_DS4;
      iNoteE = NOTE_E4;
      iNoteF = NOTE_F4;
      iNoteFS = NOTE_FS4;
      iNoteG = NOTE_G4;
      iNoteGS = NOTE_GS4;
      break;
    case 4:
      // NOTE A4
      iNoteA = NOTE_A4;
      iNoteAS = NOTE_AS4;
      iNoteB = NOTE_B4;
      iNoteC = NOTE_C5;
      iNoteCS = NOTE_CS5;
      iNoteD = NOTE_D5;
      iNoteE = NOTE_E5;
      iNoteF = NOTE_F5;
      iNoteFS = NOTE_FS5;
      iNoteG = NOTE_G5;
      iNoteGS = NOTE_GS5;
      break;
    case 5:
      // NOTE A5
      iNoteA = NOTE_A5;
      iNoteAS = NOTE_AS5;
      iNoteB = NOTE_B5;
      iNoteC = NOTE_C6;
      iNoteCS = NOTE_CS6;
      iNoteD = NOTE_D6;
      iNoteDS = NOTE_DS6;
      iNoteE = NOTE_E6;
      iNoteF = NOTE_F6;
      iNoteFS = NOTE_FS6;
      iNoteG = NOTE_G6;
      iNoteGS = NOTE_GS6;
      break;
    case 6:
      // NOTE A6
      iNoteA = NOTE_A6;
      iNoteAS = NOTE_AS6;
      iNoteB = NOTE_B6;
      iNoteC = NOTE_C7;
      iNoteCS = NOTE_CS7;
      iNoteD = NOTE_D7;
      iNoteDS = NOTE_DS7;
      iNoteE = NOTE_E7;
      iNoteF = NOTE_F7;
      iNoteFS = NOTE_FS7;
      iNoteG = NOTE_G7;
      iNoteGS = NOTE_GS7;
      break;
  }
  
}

pitches.h

/*****************************************************************
 * Pitches NOTE_B0 <=> NOTE_DS8 - NOTE_A4 is "A" measured at 440Hz
 *****************************************************************/

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1  35
#define NOTE_D1  37
#define NOTE_DS1  39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1  46
#define NOTE_G1  49
#define NOTE_GS1  52
#define NOTE_A1  55
#define NOTE_AS1  58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2  69
#define NOTE_D2  73
#define NOTE_DS2  78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2  93
#define NOTE_G2  98
#define NOTE_GS2  104
#define NOTE_A2  110
#define NOTE_AS2  117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3  139
#define NOTE_D3  147
#define NOTE_DS3  156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3  208
#define NOTE_A3  220
#define NOTE_AS3  233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4  277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4  370
#define NOTE_G4  392
#define NOTE_GS4  415
#define NOTE_A4  440
#define NOTE_AS4  466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5  554
#define NOTE_D5  587
#define NOTE_DS5  622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5  740
#define NOTE_G5  784
#define NOTE_GS5  831
#define NOTE_A5  880
#define NOTE_AS5  932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6  1109
#define NOTE_D6  1175
#define NOTE_DS6  1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6  1480
#define NOTE_G6  1568
#define NOTE_GS6  1661
#define NOTE_A6  1760
#define NOTE_AS6  1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7  2217
#define NOTE_D7  2349
#define NOTE_DS7  2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7  2960
#define NOTE_G7  3136
#define NOTE_GS7  3322
#define NOTE_A7  3520
#define NOTE_AS7  3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8  4435
#define NOTE_D8  4699
#define NOTE_DS8  4978

setup.ino

// Setup
void setup() {

  // Setup Keyboard
  setupKeyboard();

  // Mozzi Start
  startMozzi( CONTROL_RATE );
  // Sets Attack and Decay Levels; assumes Sustain, Decay, and Idle times
  envelope1.setADLevels(200,200);
  // Sets Decay time in milliseconds
  envelope1.setDecayTime(200);
  // Sustain Time setting for envelope1
  envelope1.setSustainTime(52500);

}

——

People can contact us: https://www.donluc.com/?page_id=1927

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
  • IoT
  • Robotics
  • Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
  • Unmanned Vehicles Terrestrial and Marine
  • Research & Development (R & D)

Instructor and E-Mentor

  • IoT
  • PIC Microcontrollers
  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics

Follow Us

J. Luc Paquin – Curriculum Vitae – 2022 English & Español
https://www.jlpconsultants.com/luc/

Web: https://www.donluc.com/
Web: https://www.jlpconsultants.com/
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/

Don Luc

Project #22: Synthesizer – 4 Stages – Mk11

——

#DonLucElectronics #DonLuc #Synthesizer #Mozzi #Keyboard #ADSREnvelope #Arduino #SparkFunRedBoard #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant

——

4 Stages

——

4 Stages

——

4 Stages

——

4 Stages of an ADSR Envelope

An ADSR envelope features these four stages.

  • 1 Attack: The attack phase begins the moment a key is pressed. This phase determines how quickly a sound reaches full volume before entering the decay phase. On an analog synthesizer, this phase is typically instantaneous. Some modern synthesizers allow for the attack time to be delayed.
  • 2 Decay: The decay phase determines the length of the drop from the peak level to the sustain level of a sound. The decay time can often be altered to change the overall sound. For instance, a short attack and a long decay will produce a sound that reaches maximum amplitude quickly and falls slowly to the sustain level.
  • 3 Sustain: The sustain phase does not specify a length of time. Instead, it determines the volume of a sound for the entire hold time between the decay and release phases.
  • 4 Release: The final phase determines the speed at which a sound ends from the moment you release the key. Depending on the desired sound, the release time can be short or long.

DL2208Mk04

1 x SparkFun RedBoard
7 x Momentary Button – Panel Mount (Blue)
5 x Momentary Button – Panel Mount (Black)
12 x 10K Ohm Resistor
5 x 10k Ohm Slide Linear Taper Pot – X-Large
5 x Slide Potentiometer Knob – X-Large
1 x Perfboard 13.5 cm x 11 cm
1 x SparkFun Solderable Breadboard
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x SparkFun ProtoShield
1 x Insignia Speakers
1 x SparkFun Cerberus USB Cable

SparkFun RedBoard

LP0 – Analog A0 – Blue
LP1 – Analog A1 – Green
LP2 – Analog A2 – Grey
LP3 – Analog A3 – Yellow
LP4 – Analog A4 – Purple
KY1 – 1
KY2 – 2
KY3 – 3
KY4 – 4
KY5 – 5
KY6 – 6
KY7 – 7
KY8 – 8
SPK – 9
KY10 – 10
KY11 – 11
KY12 – 12
KY13 – 13
VIN – +5V
GND – GND

DL2208Mk04p.ino

/* ***** Don Luc Electronics © *****
Software Version Information
Project #22: Synthesizer - 4 Stages - Mk11
22-11
DL2208Mk04p.ino
1 x SparkFun RedBoard
7 x Momentary Button - Panel Mount (Blue)
5 x Momentary Button - Panel Mount (Black)
12 x 1K Ohm Resistor
5 x 10k Ohm Slide Linear Taper Pot - X-Large
5 x Slide Potentiometer Knob - X-Large
1 x Perfboard 13.5 cm x 11 cm
1 x SparkFun Solderable Breadboard
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x SparkFun ProtoShield
1 x Insignia Speakers
1 x SparkFun Cerberus USB Cable
*/

// Include the Library Code
// Pitches
#include "pitches.h"
// Mozzi
#include <MozziGuts.h>
// Oscillator
#include <Oscil.h>
// Sine Wave Table For Oscillator
#include <tables/sin2048_int8.h>
// ADSR envelope generator
#include <ADSR.h>

// Simple Keyboard
// Minimum reading of the button that generates a note
const int iKeyboard1 = 1;
const int iKeyboard2 = 2;
const int iKeyboard3 = 3;
const int iKeyboard4 = 4;
const int iKeyboard5 = 5;
const int iKeyboard6 = 6;
const int iKeyboard7 = 7;
const int iKeyboard8 = 8;
const int iKeyboard10 = 10;
const int iKeyboard11 = 11;
const int iKeyboard12 = 12;
const int iKeyboard13 = 13;
// Button is pressed
int iB1 = 1;
int iB2 = 1;
int iB3 = 1;
int iB4 = 1;
int iB5 = 1;
int iB6 = 1;
int iB7 = 1;
int iB8 = 1;
int iB10 = 1;
int iB11 = 1;
int iB12 = 1;
int iB13 = 1;

// Set the input for the potentiometer for Frequency to analog pin 2
const int potFreq = A2;
int iFreg = 1;
int iNoteA = 0;
int iNoteAS = 0;
int iNoteB = 0;
int iNoteC = 0;
int iNoteCS = 0;
int iNoteD = 0;
int iNoteDS = 0;
int iNoteE = 0;
int iNoteF = 0;
int iNoteFS = 0;
int iNoteG = 0;
int iNoteGS = 0;

// Potentiometer
int iPot3 = A3;
int iPot4 = A4;

//Oscillator Functions declared for output envelope 1 
// Sine Wave
Oscil <2048, AUDIO_RATE> aSin1(SIN2048_DATA);

// ADSR declaration/definition
// Comment out to use control rate of 128
#define CONTROL_RATE 128
ADSR <CONTROL_RATE, CONTROL_RATE> envelope1;

// Set the input for the potentiometer Attack to analog pin 1
const int potAttack = A0;
// Attack
int attack_level = 0;
int iAttack = 0;

// Set the input for the potentiometer for Decay to analog pin 2
const int potDecay = A1;
// Decay
int decay_level = 0;
int iDecay = 0;

// Software Version Information
String sver = "22-11";

void loop() {

  // Audio Hook
  audioHook();
  
}

getKeyboard.ino

// getKeyboard
// setupKeyboard
void setupKeyboard() {

  // Initialize the button pin as an input
  pinMode(iKeyboard1, INPUT_PULLUP);
  pinMode(iKeyboard2, INPUT_PULLUP);
  pinMode(iKeyboard3, INPUT_PULLUP);
  pinMode(iKeyboard4, INPUT_PULLUP);
  pinMode(iKeyboard5, INPUT_PULLUP);
  pinMode(iKeyboard6, INPUT_PULLUP);
  pinMode(iKeyboard7, INPUT_PULLUP);
  pinMode(iKeyboard8, INPUT_PULLUP);
  pinMode(iKeyboard10, INPUT_PULLUP);
  pinMode(iKeyboard11, INPUT_PULLUP);
  pinMode(iKeyboard12, INPUT_PULLUP);
  pinMode(iKeyboard13, INPUT_PULLUP);
 
}
// isKeyboard
void isKeyboard() {

  // Choose envelope levels
  // attack_level
  iAttack = mozziAnalogRead( potAttack );
  attack_level = map( iAttack, 0, 1023, 100, 400);
  // Attack Level
  envelope1.setAttackLevel( attack_level );
  // decay_level
  iDecay = mozziAnalogRead( potDecay );
  decay_level = map( iDecay, 0, 1023, 50, 255);
  // Decay Level
  envelope1.setDecayLevel( decay_level );

  // Read the state of the button value 1
  if ( digitalRead(iKeyboard1) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 1
    iB1 = iB1 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteA);

  }
  else
  {
    
    iB1 = iB1 - 1;

  }

  // Read the state of the button value 2
  if ( digitalRead(iKeyboard2) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 2
    iB2 = iB2 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteAS);

  }
  else
  {
    
    iB2 = iB2 - 1;
 
  }

  // Read the state of the button value 3
  if ( digitalRead(iKeyboard3) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 3
    iB3 = iB3 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteB);

  }
  else
  {
    
    iB3 = iB3 - 1;
 
  }

  // Read the state of the button value 4
  if ( digitalRead(iKeyboard4) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 4
    iB4 = iB4 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteC);

  }
  else
  {
    
    iB4 = iB4 - 1;
 
  }

  // Read the state of the button value 5
  if ( digitalRead(iKeyboard5) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 5
    iB5 = iB5 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteCS);

  }
  else
  {
    
    iB5 = iB5 - 1;
 
  }

  // Read the state of the button value 6
  if ( digitalRead(iKeyboard6) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 6
    iB6 = iB6 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteD);

  }
  else
  {
    
    iB6 = iB6 - 1;

  }

  // Read the state of the button value 7
  if ( digitalRead(iKeyboard7) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 7
    iB7 = iB7 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteDS);

  }
  else
  {
    
    iB7 = iB7 - 1;
 
  }

  // Read the state of the button value 8
  if ( digitalRead(iKeyboard8) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 8
    iB8 = iB8 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteE);

  }
  else
  {
    
    iB8 = iB8 - 1;

  }

  // Read the state of the button value 10
  if ( digitalRead(iKeyboard10) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 10
    iB10 = iB10 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteF);

  }
  else
  {
    
    iB10 = iB10 - 1;

  }

  // Read the state of the button value 11
  if ( digitalRead(iKeyboard11) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 11
    iB11 = iB11 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteFS);

  }
  else
  {
    
    iB11 = iB11 - 1;
 
  }

  // Read the state of the button value 12
  if ( digitalRead(iKeyboard12) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 12
    iB12 = iB12 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteG);

  }
  else
  {
    
    iB12 = iB12 - 1;
    
  }

  // Read the state of the button value 13
  if ( digitalRead(iKeyboard13) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 13
    iB13 = iB13 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteGS);

  }
  else
  {
    
    iB13 = iB13 - 1;

  }

}

getMozzi.ino

// Mozzi
// Update Control
void updateControl(){

  // Frequency
  isPitches();
  
  // Keyboard
  isKeyboard();

}
// Update Audio
int updateAudio()
{

  // Update Audio
  // ADSR declaration/definition
  envelope1.update();
  // >>8 for AUDIO_MODE STANDARD
  return (int) (envelope1.next() * aSin1.next())>>8;

}

getPitches.ino

// Pitches
// isPitches
void isPitches(){
  
  // Frequency
  // Value is 0-1023
  iFreg = mozziAnalogRead(potFreq);
  iFreg = map(iFreg, 0, 1023, 2, 6);

  // Range Frequency Note Low => High
  switch ( iFreg ) {
    case 1:
      // NOTE A1
      iNoteA = NOTE_A1;
      iNoteAS = NOTE_AS1;
      iNoteB = NOTE_B1;
      iNoteC = NOTE_C2;
      iNoteCS = NOTE_CS2;
      iNoteD = NOTE_D2;
      iNoteDS = NOTE_DS2;
      iNoteE = NOTE_E2;
      iNoteF = NOTE_F2;
      iNoteFS = NOTE_FS2;
      iNoteG = NOTE_G2;
      iNoteGS = NOTE_GS2;
      break;
    case 2:
      // NOTE A2
      iNoteA = NOTE_A2;
      iNoteAS = NOTE_AS2;
      iNoteB = NOTE_B2;
      iNoteC = NOTE_C3;
      iNoteCS = NOTE_CS3;
      iNoteD = NOTE_D3;
      iNoteDS = NOTE_DS3;
      iNoteE = NOTE_E3;
      iNoteF = NOTE_F3;
      iNoteFS = NOTE_FS3;
      iNoteG = NOTE_G3;
      iNoteGS = NOTE_GS3;
      break;
    case 3:
      // NOTE A3
      iNoteA = NOTE_A3;
      iNoteAS = NOTE_AS3;
      iNoteB = NOTE_B3;
      iNoteC = NOTE_C4;
      iNoteD = NOTE_D4;
      iNoteDS = NOTE_DS4;
      iNoteE = NOTE_E4;
      iNoteF = NOTE_F4;
      iNoteFS = NOTE_FS4;
      iNoteG = NOTE_G4;
      iNoteGS = NOTE_GS4;
      break;
    case 4:
      // NOTE A4
      iNoteA = NOTE_A4;
      iNoteAS = NOTE_AS4;
      iNoteB = NOTE_B4;
      iNoteC = NOTE_C5;
      iNoteCS = NOTE_CS5;
      iNoteD = NOTE_D5;
      iNoteE = NOTE_E5;
      iNoteF = NOTE_F5;
      iNoteFS = NOTE_FS5;
      iNoteG = NOTE_G5;
      iNoteGS = NOTE_GS5;
      break;
    case 5:
      // NOTE A5
      iNoteA = NOTE_A5;
      iNoteAS = NOTE_AS5;
      iNoteB = NOTE_B5;
      iNoteC = NOTE_C6;
      iNoteCS = NOTE_CS6;
      iNoteD = NOTE_D6;
      iNoteDS = NOTE_DS6;
      iNoteE = NOTE_E6;
      iNoteF = NOTE_F6;
      iNoteFS = NOTE_FS6;
      iNoteG = NOTE_G6;
      iNoteGS = NOTE_GS6;
      break;
    case 6:
      // NOTE A6
      iNoteA = NOTE_A6;
      iNoteAS = NOTE_AS6;
      iNoteB = NOTE_B6;
      iNoteC = NOTE_C7;
      iNoteCS = NOTE_CS7;
      iNoteD = NOTE_D7;
      iNoteDS = NOTE_DS7;
      iNoteE = NOTE_E7;
      iNoteF = NOTE_F7;
      iNoteFS = NOTE_FS7;
      iNoteG = NOTE_G7;
      iNoteGS = NOTE_GS7;
      break;
  }
  
}

pitches.h

/*****************************************************************
 * Pitches NOTE_B0 <=> NOTE_DS8 - NOTE_A4 is "A" measured at 440Hz
 *****************************************************************/

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1  35
#define NOTE_D1  37
#define NOTE_DS1  39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1  46
#define NOTE_G1  49
#define NOTE_GS1  52
#define NOTE_A1  55
#define NOTE_AS1  58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2  69
#define NOTE_D2  73
#define NOTE_DS2  78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2  93
#define NOTE_G2  98
#define NOTE_GS2  104
#define NOTE_A2  110
#define NOTE_AS2  117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3  139
#define NOTE_D3  147
#define NOTE_DS3  156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3  208
#define NOTE_A3  220
#define NOTE_AS3  233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4  277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4  370
#define NOTE_G4  392
#define NOTE_GS4  415
#define NOTE_A4  440
#define NOTE_AS4  466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5  554
#define NOTE_D5  587
#define NOTE_DS5  622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5  740
#define NOTE_G5  784
#define NOTE_GS5  831
#define NOTE_A5  880
#define NOTE_AS5  932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6  1109
#define NOTE_D6  1175
#define NOTE_DS6  1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6  1480
#define NOTE_G6  1568
#define NOTE_GS6  1661
#define NOTE_A6  1760
#define NOTE_AS6  1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7  2217
#define NOTE_D7  2349
#define NOTE_DS7  2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7  2960
#define NOTE_G7  3136
#define NOTE_GS7  3322
#define NOTE_A7  3520
#define NOTE_AS7  3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8  4435
#define NOTE_D8  4699
#define NOTE_DS8  4978

setup.ino

// Setup
void setup() {

  // Setup Keyboard
  setupKeyboard();

  // Mozzi Start
  startMozzi( CONTROL_RATE );
  // Sets Attack and Decay Levels; assumes Sustain, Decay, and Idle times
  envelope1.setADLevels(200,200);
  // Sets Decay time in milliseconds
  envelope1.setDecayTime(200);
  // Sustain Time setting for envelope1
  envelope1.setSustainTime(52500);

}

——

People can contact us: https://www.donluc.com/?page_id=1927

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
  • IoT
  • Robotics
  • Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
  • Unmanned Vehicles Terrestrial and Marine
  • Research & Development (R & D)

Instructor and E-Mentor

  • IoT
  • PIC Microcontrollers
  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics

Follow Us

J. Luc Paquin – Curriculum Vitae – 2022 English & Español
https://www.jlpconsultants.com/luc/

Web: https://www.donluc.com/
Web: https://www.jlpconsultants.com/
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/

Don Luc

Project #22: Synthesizer – ADSR Envelope – Mk10

——

#DonLucElectronics #DonLuc #Synthesizer #Mozzi #Keyboard #ADSREnvelope #Arduino #SparkFunRedBoard #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant

——

ADSR Envelope

——

ADSR Envelope

——

ADSR Envelope

——

What Is an Envelope in Music?

An envelope is a term used to describe the evolution of a sound in a piece of music. Envelopes are fed through an envelope generator, the component within an analog synthesizer that signals when and how a sound should change. The envelope defines the trajectory and modulation of a sound, while the envelope generator controls the behavior of the envelope.

What Is an ADSR Envelope?

An ADSR envelope is a type of envelope control mechanism commonly found in the synthesizer and samplers used in electronic music. ADSR stands for the envelope’s four stages of modulation: attack, decay, sustain, and release. These stages control the level of the sound from the moment you press a key or advance a music sequencer.

In sound design, ADSR envelopes are typically used to control the loudness of a sound. ADSR envelopes typically produce a sound that takes the shape of a waveform rising in the attack stage, slightly declining during the decay stage, plateauing during the sustain stage, and finally falling at the return stage.

DL2208Mk03

1 x SparkFun RedBoard
7 x Momentary Button – Panel Mount (Blue)
5 x Momentary Button – Panel Mount (Black)
12 x 10K Ohm Resistor
5 x 10k Ohm Slide Linear Taper Pot – X-Large
5 x Slide Potentiometer Knob – X-Large
1 x Perfboard 13.5 cm x 11 cm
1 x SparkFun Solderable Breadboard
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x SparkFun ProtoShield
1 x Insignia Speakers
1 x SparkFun Cerberus USB Cable

SparkFun RedBoard

LP0 – Analog A0 – Blue
LP1 – Analog A1 – Green
LP2 – Analog A2 – Grey
LP3 – Analog A3 – Yellow
LP4 – Analog A4 – Purple
KY1 – 1
KY2 – 2
KY3 – 3
KY4 – 4
KY5 – 5
KY6 – 6
KY7 – 7
KY8 – 8
SPK – 9
KY10 – 10
KY11 – 11
KY12 – 12
KY13 – 13
VIN – +5V
GND – GND

——

DL2208Mk03p.ino

/* ***** Don Luc Electronics © *****
Software Version Information
Project #22: Synthesizer - ADSR Envelope - Mk10
22-10
DL2208Mk03p.ino
1 x SparkFun RedBoard
7 x Momentary Button - Panel Mount (Blue)
5 x Momentary Button - Panel Mount (Black)
12 x 1K Ohm Resistor
5 x 10k Ohm Slide Linear Taper Pot - X-Large
5 x Slide Potentiometer Knob - X-Large
1 x Perfboard 13.5 cm x 11 cm
1 x SparkFun Solderable Breadboard
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x SparkFun ProtoShield
1 x Insignia Speakers
1 x SparkFun Cerberus USB Cable
*/

// Include the Library Code
// Pitches
#include "pitches.h"
// Mozzi
#include <MozziGuts.h>
// Oscillator
#include <Oscil.h>
// Sine Wave Table For Oscillator
#include <tables/sin2048_int8.h>
// ADSR envelope generator
#include <ADSR.h>

// Simple Keyboard
// Minimum reading of the button that generates a note
const int iKeyboard1 = 1;
const int iKeyboard2 = 2;
const int iKeyboard3 = 3;
const int iKeyboard4 = 4;
const int iKeyboard5 = 5;
const int iKeyboard6 = 6;
const int iKeyboard7 = 7;
const int iKeyboard8 = 8;
const int iKeyboard10 = 10;
const int iKeyboard11 = 11;
const int iKeyboard12 = 12;
const int iKeyboard13 = 13;
// Button is pressed
int iB1 = 1;
int iB2 = 1;
int iB3 = 1;
int iB4 = 1;
int iB5 = 1;
int iB6 = 1;
int iB7 = 1;
int iB8 = 1;
int iB10 = 1;
int iB11 = 1;
int iB12 = 1;
int iB13 = 1;

// Set the input for the potentiometer for Frequency to analog pin 3
//const int potFreq = A3;
int iFreg = 1;
int iNoteA = 0;
int iNoteAS = 0;
int iNoteB = 0;
int iNoteC = 0;
int iNoteCS = 0;
int iNoteD = 0;
int iNoteDS = 0;
int iNoteE = 0;
int iNoteF = 0;
int iNoteFS = 0;
int iNoteG = 0;
int iNoteGS = 0;

// Potentiometer
int iPot2 = A2;
int iPot3 = A3;
int iPot4 = A4;

//Oscillator Functions declared for output envelope 1 
// Sine Wave
Oscil <2048, AUDIO_RATE> aSin1(SIN2048_DATA);

// ADSR declaration/definition
// Comment out to use control rate of 128
#define CONTROL_RATE 128
ADSR <CONTROL_RATE, CONTROL_RATE> envelope1;

// Set the input for the potentiometer Attack to analog pin 1
const int potAttack = A0;
// Attack
int attack_level = 0;
int iAttack = 0;

// Set the input for the potentiometer for Decay to analog pin 2
const int potDecay = A1;
// Decay
int decay_level = 0;
int iDecay = 0;

// Software Version Information
String sver = "22-10";

void loop() {

  // Audio Hook
  audioHook();
  
}

getKeyboard.ino

// getKeyboard
// setupKeyboard
void setupKeyboard() {

  // Initialize the button pin as an input
  pinMode(iKeyboard1, INPUT_PULLUP);
  pinMode(iKeyboard2, INPUT_PULLUP);
  pinMode(iKeyboard3, INPUT_PULLUP);
  pinMode(iKeyboard4, INPUT_PULLUP);
  pinMode(iKeyboard5, INPUT_PULLUP);
  pinMode(iKeyboard6, INPUT_PULLUP);
  pinMode(iKeyboard7, INPUT_PULLUP);
  pinMode(iKeyboard8, INPUT_PULLUP);
  pinMode(iKeyboard10, INPUT_PULLUP);
  pinMode(iKeyboard11, INPUT_PULLUP);
  pinMode(iKeyboard12, INPUT_PULLUP);
  pinMode(iKeyboard13, INPUT_PULLUP);
 
}
// isKeyboard
void isKeyboard() {

  // Choose envelope levels
  // attack_level
  iAttack = mozziAnalogRead( potAttack );
  attack_level = map( iAttack, 0, 1023, 0, 255);
  // decay_level
  iDecay = mozziAnalogRead( potDecay );
  decay_level = map( iDecay, 0, 1023, 0, 255);
  // set AD Levels
  envelope1.setADLevels(attack_level,decay_level);

  // Read the state of the button value 1
  if ( digitalRead(iKeyboard1) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 1
    iB1 = iB1 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteA);

  }
  else
  {
    
    iB1 = iB1 - 1;

  }

  // Read the state of the button value 2
  if ( digitalRead(iKeyboard2) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 2
    iB2 = iB2 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteAS);

  }
  else
  {
    
    iB2 = iB2 - 1;
 
  }

  // Read the state of the button value 3
  if ( digitalRead(iKeyboard3) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 3
    iB3 = iB3 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteB);

  }
  else
  {
    
    iB3 = iB3 - 1;
 
  }

  // Read the state of the button value 4
  if ( digitalRead(iKeyboard4) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 4
    iB4 = iB4 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteC);

  }
  else
  {
    
    iB4 = iB4 - 1;
 
  }

  // Read the state of the button value 5
  if ( digitalRead(iKeyboard5) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 5
    iB5 = iB5 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteCS);

  }
  else
  {
    
    iB5 = iB5 - 1;
 
  }

  // Read the state of the button value 6
  if ( digitalRead(iKeyboard6) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 6
    iB6 = iB6 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteD);

  }
  else
  {
    
    iB6 = iB6 - 1;

  }

  // Read the state of the button value 7
  if ( digitalRead(iKeyboard7) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 7
    iB7 = iB7 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteDS);

  }
  else
  {
    
    iB7 = iB7 - 1;
 
  }

  // Read the state of the button value 8
  if ( digitalRead(iKeyboard8) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 8
    iB8 = iB8 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteE);

  }
  else
  {
    
    iB8 = iB8 - 1;

  }

  // Read the state of the button value 10
  if ( digitalRead(iKeyboard10) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 10
    iB10 = iB10 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteF);

  }
  else
  {
    
    iB10 = iB10 - 1;

  }

  // Read the state of the button value 11
  if ( digitalRead(iKeyboard11) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 11
    iB11 = iB11 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteFS);

  }
  else
  {
    
    iB11 = iB11 - 1;
 
  }

  // Read the state of the button value 12
  if ( digitalRead(iKeyboard12) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 12
    iB12 = iB12 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteG);

  }
  else
  {
    
    iB12 = iB12 - 1;
    
  }

  // Read the state of the button value 13
  if ( digitalRead(iKeyboard13) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 13
    iB13 = iB13 + 1;
    // ADSR declaration/definition
    envelope1.noteOn();
    aSin1.setFreq(iNoteGS);

  }
  else
  {
    
    iB13 = iB13 - 1;

  }

}

getMozzi.ino

// Mozzi
// Update Control
void updateControl(){

  // Frequency
  isPitches();
  
  // Keyboard
  isKeyboard();

}
// Update Audio
int updateAudio()
{

  // Update Audio
  // ADSR declaration/definition
  envelope1.update();
  // >>8 for AUDIO_MODE STANDARD
  return (int) (envelope1.next() * aSin1.next())>>8;

}

getPitches.ino

// Pitches
// isPitches
void isPitches(){
  
  // Frequency
  // Value is 0-1023
  //iFreg = mozziAnalogRead(potFreq);
  //iFreg = map(iFreg, 0, 1023, 3, 6);
  iFreg = 5;

  // Range Frequency Note Low => High
  switch ( iFreg ) {
    case 1:
      // NOTE A1
      iNoteA = NOTE_A1;
      iNoteAS = NOTE_AS1;
      iNoteB = NOTE_B1;
      iNoteC = NOTE_C2;
      iNoteCS = NOTE_CS2;
      iNoteD = NOTE_D2;
      iNoteDS = NOTE_DS2;
      iNoteE = NOTE_E2;
      iNoteF = NOTE_F2;
      iNoteFS = NOTE_FS2;
      iNoteG = NOTE_G2;
      iNoteGS = NOTE_GS2;
      break;
    case 2:
      // NOTE A2
      iNoteA = NOTE_A2;
      iNoteAS = NOTE_AS2;
      iNoteB = NOTE_B2;
      iNoteC = NOTE_C3;
      iNoteCS = NOTE_CS3;
      iNoteD = NOTE_D3;
      iNoteDS = NOTE_DS3;
      iNoteE = NOTE_E3;
      iNoteF = NOTE_F3;
      iNoteFS = NOTE_FS3;
      iNoteG = NOTE_G3;
      iNoteGS = NOTE_GS3;
      break;
    case 3:
      // NOTE A3
      iNoteA = NOTE_A3;
      iNoteAS = NOTE_AS3;
      iNoteB = NOTE_B3;
      iNoteC = NOTE_C4;
      iNoteD = NOTE_D4;
      iNoteDS = NOTE_DS4;
      iNoteE = NOTE_E4;
      iNoteF = NOTE_F4;
      iNoteFS = NOTE_FS4;
      iNoteG = NOTE_G4;
      iNoteGS = NOTE_GS4;
      break;
    case 4:
      // NOTE A4
      iNoteA = NOTE_A4;
      iNoteAS = NOTE_AS4;
      iNoteB = NOTE_B4;
      iNoteC = NOTE_C5;
      iNoteCS = NOTE_CS5;
      iNoteD = NOTE_D5;
      iNoteE = NOTE_E5;
      iNoteF = NOTE_F5;
      iNoteFS = NOTE_FS5;
      iNoteG = NOTE_G5;
      iNoteGS = NOTE_GS5;
      break;
    case 5:
      // NOTE A5
      iNoteA = NOTE_A5;
      iNoteAS = NOTE_AS5;
      iNoteB = NOTE_B5;
      iNoteC = NOTE_C6;
      iNoteCS = NOTE_CS6;
      iNoteD = NOTE_D6;
      iNoteDS = NOTE_DS6;
      iNoteE = NOTE_E6;
      iNoteF = NOTE_F6;
      iNoteFS = NOTE_FS6;
      iNoteG = NOTE_G6;
      iNoteGS = NOTE_GS6;
      break;
    case 6:
      // NOTE A6
      iNoteA = NOTE_A6;
      iNoteAS = NOTE_AS6;
      iNoteB = NOTE_B6;
      iNoteC = NOTE_C7;
      iNoteCS = NOTE_CS7;
      iNoteD = NOTE_D7;
      iNoteDS = NOTE_DS7;
      iNoteE = NOTE_E7;
      iNoteF = NOTE_F7;
      iNoteFS = NOTE_FS7;
      iNoteG = NOTE_G7;
      iNoteGS = NOTE_GS7;
      break;
  }
  
}

pitches.h

/*****************************************************************
 * Pitches NOTE_B0 <=> NOTE_DS8 - NOTE_A4 is "A" measured at 440Hz
 *****************************************************************/

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1  35
#define NOTE_D1  37
#define NOTE_DS1  39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1  46
#define NOTE_G1  49
#define NOTE_GS1  52
#define NOTE_A1  55
#define NOTE_AS1  58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2  69
#define NOTE_D2  73
#define NOTE_DS2  78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2  93
#define NOTE_G2  98
#define NOTE_GS2  104
#define NOTE_A2  110
#define NOTE_AS2  117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3  139
#define NOTE_D3  147
#define NOTE_DS3  156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3  208
#define NOTE_A3  220
#define NOTE_AS3  233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4  277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4  370
#define NOTE_G4  392
#define NOTE_GS4  415
#define NOTE_A4  440
#define NOTE_AS4  466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5  554
#define NOTE_D5  587
#define NOTE_DS5  622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5  740
#define NOTE_G5  784
#define NOTE_GS5  831
#define NOTE_A5  880
#define NOTE_AS5  932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6  1109
#define NOTE_D6  1175
#define NOTE_DS6  1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6  1480
#define NOTE_G6  1568
#define NOTE_GS6  1661
#define NOTE_A6  1760
#define NOTE_AS6  1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7  2217
#define NOTE_D7  2349
#define NOTE_DS7  2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7  2960
#define NOTE_G7  3136
#define NOTE_GS7  3322
#define NOTE_A7  3520
#define NOTE_AS7  3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8  4435
#define NOTE_D8  4699
#define NOTE_DS8  4978

setup.ino

// Setup
void setup() {

  // Setup Keyboard
  setupKeyboard();

  // Mozzi Start
  startMozzi( CONTROL_RATE );
  // Sets Attack and Decay Levels; assumes Sustain, Decay, and Idle times
  envelope1.setADLevels(200,200);
  // Sets Decay time in milliseconds
  envelope1.setDecayTime(100);
  // Sustain Time setting for envelope1
  envelope1.setSustainTime(32500);

}

——

People can contact us: https://www.donluc.com/?page_id=1927

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
  • IoT
  • Robotics
  • Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
  • Unmanned Vehicles Terrestrial and Marine
  • Research & Development (R & D)

Instructor and E-Mentor

  • IoT
  • PIC Microcontrollers
  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics

Follow Us

J. Luc Paquin – Curriculum Vitae – 2022 English & Español
https://www.jlpconsultants.com/luc/

Web: https://www.donluc.com/
Web: https://www.jlpconsultants.com/
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/

Don Luc

Project #22: Synthesizer – Momentary Button – Mk09

——

#DonLucElectronics #DonLuc #Synthesizer #Mozzi #Keyboard #ADSREnvelope #Arduino #AdafruitMETROM0Express #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant

——

Momentary Button

——

Momentary Button

——

Momentary Button

——

Momentary Button – Panel Mount

It’s your basic black or blue action button. This is a very useful, small, panel-mount momentary switch. It is a SPST N.O. with the threaded portion being 6.75 mm in diameter. This button is perfect for basic On/Off functions. Overall length including leads and has small solder lugs for connection. These momentary buttons are rated up to 0.5A and 250VAC.

Momentary button connect two points in a circuit when you press them. Turns on and off a light emitting LED. When the button is open there is no connection between the two legs of the button, so the pin is connected to ground, through the pull-down resistor, and we read a LOW. When the button is closed, it makes a connection between its two legs, connecting the pin to 5 volts, so that we read a HIGH.

You can also wire this circuit the opposite way, with a pullup resistor keeping the input HIGH, and going LOW when the button is pressed. If so, the behavior of the sketch will be reversed, with the LED normally on and turning off when you press the button.

DL2208Mk02

1 x Adafruit METRO M0 Express
8 x Momentary Button – Panel Mount (Blue)
5 x Momentary Button – Panel Mount (Black)
13 x 10K Ohm Resistor
1 x LED Red 5mm
1 x SparkFun Cerberus USB Cable

Adafruit METRO M0 Express

KY0 – 0
KY1 – 1
KY2 – 2
KY3 – 3
KY4 – 4
KY5 – 5
KY6 – 6
KY7 – 7
KY8 – 8
LEDR – 9
KY10 – 10
KY11 – 11
KY12 – 12
KY13 – 13
VIN – +5V
GND – GND

——

DL2208Mk02p.ino

/* ***** Don Luc Electronics © *****
Software Version Information
Project #22: Synthesizer - Momentary Button - Mk09
22-09
DL2208Mk02p.ino
1 x Adafruit METRO M0 Express
8 x Momentary Button - Panel Mount (Blue)
5 x Momentary Button - Panel Mount (Black)
13 x 1K Ohm Resistor
1 x LED Red 5mm
1 x SparkFun Cerberus USB Cable
*/

// Include the Library Code


// Simple Keyboard
// Minimum reading of the button that generates a note
//const int iKeyboard0 = 0;
const int iKeyboard1 = 1;
const int iKeyboard2 = 2;
const int iKeyboard3 = 3;
const int iKeyboard4 = 4;
const int iKeyboard5 = 5;
const int iKeyboard6 = 6;
const int iKeyboard7 = 7;
const int iKeyboard8 = 8;
const int iKeyboard10 = 10;
const int iKeyboard11 = 11;
const int iKeyboard12 = 12;
const int iKeyboard13 = 13;
// Button is pressed
int iB0 = 1;
int iB1 = 1;
int iB2 = 1;
int iB3 = 1;
int iB4 = 1;
int iB5 = 1;
int iB6 = 1;
int iB7 = 1;
int iB8 = 1;
int iB10 = 1;
int iB11 = 1;
int iB12 = 1;
int iB13 = 1;

// The number of the LED Red pin 9
const int iLedR =  9;

// Software Version Information
String sver = "22-09";

void loop() {

  // isKeyboard
  isKeyboard();
  
}

getKeyboard.ino

// getKeyboard
// setupKeyboard
void setupKeyboard() {

  // Initialize the button pin as an input
//  pinMode(iKeyboard0, INPUT_PULLUP);
  pinMode(iKeyboard1, INPUT_PULLUP);
  pinMode(iKeyboard2, INPUT_PULLUP);
  pinMode(iKeyboard3, INPUT_PULLUP);
  pinMode(iKeyboard4, INPUT_PULLUP);
  pinMode(iKeyboard5, INPUT_PULLUP);
  pinMode(iKeyboard6, INPUT_PULLUP);
  pinMode(iKeyboard7, INPUT_PULLUP);
  pinMode(iKeyboard8, INPUT_PULLUP);
  pinMode(iKeyboard10, INPUT_PULLUP);
  pinMode(iKeyboard11, INPUT_PULLUP);
  pinMode(iKeyboard12, INPUT_PULLUP);
  pinMode(iKeyboard13, INPUT_PULLUP);
 
}
// isKeyboard
void isKeyboard() {

/*
  // Read the state of the button value 0
  if ( digitalRead(iKeyboard0) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 0
    iB0 = iB0 + 1;
    // Turn LED Red on
    digitalWrite(iLedR, HIGH );

  }
  else
  {
    
    iB0 = iB0 - 1;
    // Turn LED Red off
    digitalWrite(iLedR, LOW );
    
  }
*/
  // Read the state of the button value 1
  if ( digitalRead(iKeyboard1) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 1
    iB1 = iB1 + 1;
    // Turn LED Red on
    digitalWrite(iLedR, HIGH );

  }
  else
  {
    
    iB1 = iB1 - 1;
    // Turn LED Red off
    digitalWrite(iLedR, LOW );
    
  }

  // Read the state of the button value 2
  if ( digitalRead(iKeyboard2) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 2
    iB2 = iB2 + 1;
    // Turn LED Red on
    digitalWrite(iLedR, HIGH );

  }
  else
  {
    
    iB2 = iB2 - 1;
    // Turn LED Red off
    digitalWrite(iLedR, LOW );
    
  }

  // Read the state of the button value 3
  if ( digitalRead(iKeyboard3) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 3
    iB3 = iB3 + 1;
    // Turn LED Red on
    digitalWrite(iLedR, HIGH );

  }
  else
  {
    
    iB3 = iB3 - 1;
    // Turn LED Red off
    digitalWrite(iLedR, LOW );
    
  }

  // Read the state of the button value 4
  if ( digitalRead(iKeyboard4) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 4
    iB4 = iB4 + 1;
    // Turn LED Red on
    digitalWrite(iLedR, HIGH );

  }
  else
  {
    
    iB4 = iB4 - 1;
    // Turn LED Red off
    digitalWrite(iLedR, LOW );
    
  }

  // Read the state of the button value 5
  if ( digitalRead(iKeyboard5) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 5
    iB5 = iB5 + 1;
    // Turn LED Red on
    digitalWrite(iLedR, HIGH );

  }
  else
  {
    
    iB5 = iB5 - 1;
    // Turn LED Red off
    digitalWrite(iLedR, LOW );
    
  }

  // Read the state of the button value 6
  if ( digitalRead(iKeyboard6) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 6
    iB6 = iB6 + 1;
    // Turn LED Red on
    digitalWrite(iLedR, HIGH );

  }
  else
  {
    
    iB6 = iB6 - 1;
    // Turn LED Red off
    digitalWrite(iLedR, LOW );
    
  }

  // Read the state of the button value 7
  if ( digitalRead(iKeyboard7) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 7
    iB7 = iB7 + 1;
    // Turn LED Red on
    digitalWrite(iLedR, HIGH );

  }
  else
  {
    
    iB7 = iB7 - 1;// Turn LED Red off
    digitalWrite(iLedR, LOW );
    
  }

  // Read the state of the button value 8
  if ( digitalRead(iKeyboard8) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 8
    iB8 = iB8 + 1;
    // Turn LED Red on
    digitalWrite(iLedR, HIGH );

  }
  else
  {
    
    iB8 = iB8 - 1;
    // Turn LED Red off
    digitalWrite(iLedR, LOW );
    
  }

  // Read the state of the button value 10
  if ( digitalRead(iKeyboard10) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 10
    iB10 = iB10 + 1;
    // Turn LED Red on
    digitalWrite(iLedR, HIGH );

  }
  else
  {
    
    iB10 = iB10 - 1;
    // Turn LED Red off
    digitalWrite(iLedR, LOW );
    
  }

  // Read the state of the button value 11
  if ( digitalRead(iKeyboard11) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 11
    iB11 = iB11 + 1;
    // Turn LED Red on
    digitalWrite(iLedR, HIGH );

  }
  else
  {
    
    iB11 = iB11 - 1;
    // Turn LED Red off
    digitalWrite(iLedR, LOW );
    
  }

  // Read the state of the button value 12
  if ( digitalRead(iKeyboard12) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 12
    iB12 = iB12 + 1;
    // Turn LED Red on
    digitalWrite(iLedR, HIGH );

  }
  else
  {
    
    iB12 = iB12 - 1;
    // Turn LED Red off
    digitalWrite(iLedR, LOW );
    
  }

  // Read the state of the button value 13
  if ( digitalRead(iKeyboard13) == HIGH ) {

    // Button is pressed - pullup keeps pin high normally 13
    iB13 = iB13 + 1;
    // Turn LED Red on
    digitalWrite(iLedR, HIGH );

  }
  else
  {
    
    iB13 = iB13 - 1;
    // Turn LED Red off
    digitalWrite(iLedR, LOW );
    
  }

}

setup.ino

// Setup
void setup() {

  // Setup Keyboard
  setupKeyboard();

  // Initialize the LED Red pin 9 as an output
  pinMode(iLedR, OUTPUT);
  
}

——

People can contact us: https://www.donluc.com/?page_id=1927

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
  • IoT
  • Robotics
  • Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
  • Unmanned Vehicles Terrestrial and Marine
  • Research & Development (R & D)

Instructor and E-Mentor

  • IoT
  • PIC Microcontrollers
  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics

Follow Us

J. Luc Paquin – Curriculum Vitae – 2022 English & Español
https://www.jlpconsultants.com/luc/

Web: https://www.donluc.com/
Web: https://www.jlpconsultants.com/
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/

Don Luc

Categories
Archives