Fermento Mods

From SGMK-SSAM-WIKI
Jump to: navigation, search

Back to HLab DIY labs

dusjagr's simple version 4-digit display

<syntaxhighlight lang="c">

/*

* (c) Fakufaku 2013
* This is the code for the homebrew incubator 'Fermento'
* This code is released under the CC-BY-SA 3.0 License.
* The part of the code that's used for the display on the 7-segment was ripped off the BigTime code from Nathan Seidl. I owe him a beer then.
*/
  1. include <math.h>
  1. include <PID_v1.h>
  1. define TRUE 1
  2. define FALSE 0

//Careful messing with the system color, you can damage the display if //you assign the wrong color. If you're in doubt, set it to red and load the code, //then see what the color is.

  1. define RED 1
  2. define GREEN 2
  3. define BLUE 3
  4. define YELLOW 4

int systemColor = RED; int display_brightness = 15000; //A larger number makes the display more dim. This is set correctly below. // slow continuous PWM variables

  1. define PWM_MS 50 // this changes the update speed
  2. define PWM_MIN 100
  3. define RELAY_ON LOW
  4. define RELAY_OFF HIGH

// PID loop parameter

  1. define PID_KP 50
  2. define PID_KI 1
  3. define PID_KD 1

// Some display related parameters (time in seconds, temperature in degrees Celsius)

  1. define TIME_INCREMENT 1800
  2. define MAX_TIME 356459
  3. define TEMP_INCREMENT 1
  4. define MAX_TEMP 65

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Uncomment following line for the homebrew (1-sided) PCB version //#define FERMENTO_1SIDE

  1. define FERMENTO_DUSJAGR

//Pin definitions

  1. ifdef FERMENTO_DUSJAGR

int digit1 = 13; //Display pin 12 int digit2 = 10; //Display pin 9 int digit3 = 9; //Display pin 8 int digit4 = 7; //Display pin 6

int segA = 12; //Display pin 11 int segB = 8; //Display pin 7 int segC = 5; //Display pin 4 int segD = 3; //Display pin 2 int segE = 2; //Display pin 1 int segF = 11; //Display pin 10 int segG = 6; //Display pin 5

int colons = 4; //Display pin 3

int temp_sen = A5; // to read the temperature sensor int poti_sen = A4; // to read the temperature sensor

const static int buzz = A2; const static int theButton = A1; const static int theButton2 = A0; const static int pwm_pin = A3; // Pin 4

// The interrupt of button1 is on external interrupt 0 // The interrupt of button2 is on external interrupt 1

  1. define BUTTON1_INT_VECT INT0_vect
  2. define BUTTON2_INT_VECT INT1_vect
  3. define BUTTONS_INT_SET() do \
 {                           \
   EICRA = (1<<ISC11) + (1<<ISC01); /* falling edge */ \
   EIMSK = (1<<INT1) + (1<<INT0);      \
 }                           \
 while (0)
  1. else

// The interrupt of button1 is on external interrupt 0 // The interrupt of button2 is on PCINT13 (A5), on PCIE1.

  1. define BUTTON1_INT_VECT INT0_vect
  2. define BUTTON2_INT_VECT PCINT1_vect
  3. define BUTTONS_INT_SET() do \
 {                           \
   EICRA = (1<<ISC01); /* falling edge */     \
   EIMSK = (1<<INT0);        \
   PCICR = (1 << PCIE1);     \
   PCMSK1 = (1 << PCINT13);  \
 }                           \
 while (0)
  1. endif

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


// Display status variable

  1. define TIME 1
  2. define TEMP 2

int display_status = TEMP; int backoff = 0; // just a short backoff for when we switch the display between TIME/TEMP

  1. define BACKOFFTIME 2

char disp_str[4];

// Variable to keep track of PWM window unsigned long windowStartTime;

// control variables for PID double t_incub; // input to PID (temperature in incubator) double t_incub_N; // number of samples in t_incub average double pwm_duty; // output of PID double t_set = 0; // set point (target temperature) double a_Poti; // poti value

//Specify the links and initial tuning parameters PID myPID(&t_incub, &pwm_duty, &t_set, PID_KP, PID_KI, PID_KD, DIRECT);

// display timer (freeze parameters to display for 2 seconds) int t_incub_disp;

// Timer variables unsigned long timer_seconds = 0;

//The very important 32.686kHz interrupt handler SIGNAL(TIMER2_OVF_vect) {

 if (timer_seconds > 1)
 {
   timer_seconds--;
 }
 else if (timer_seconds == 1)
 {
   // reset timer
   timer_seconds = 0;
   // turn off by setting target temperature to zero
   t_set = 0;
   // Reset the PID
   myPID.SetMode(MANUAL);
   myPID.SetMode(AUTOMATIC);
 }
 // decrement backoff
 if (backoff > 0)
   backoff--;

}

//The interrupt occurs when you push the button SIGNAL(BUTTON1_INT_VECT) {

 display_status = TEMP;
 backoff = BACKOFFTIME;

}

SIGNAL(BUTTON2_INT_VECT) {

 display_status = TIME;
 backoff = BACKOFFTIME;

}

void setup() {

 Serial.begin(57600);
 // set ADC reference to 3.3V
 analogReference(DEFAULT);
 // initialize pwm drive pin, and turn it off
 pinMode(pwm_pin, OUTPUT);
 digitalWrite(pwm_pin, HIGH);
 // initialize buzzer pin
 pinMode(buzz, OUTPUT);
 // initialize the buttons
 pinMode(theButton, INPUT);
 digitalWrite(theButton, HIGH); // pull-up
 pinMode(theButton2, INPUT);
 digitalWrite(theButton2, HIGH); // pull-up
 BUTTONS_INT_SET();
 //Setup TIMER2
 TCCR2A = 0x00;
 TCCR2B = (1<<CS22)|(1<<CS20); //Set CLK/128 or overflow interrupt every 1s
 ASSR   = (1<<AS2); //Enable asynchronous operation
 TIMSK2 = (1<<TOIE2); //Enable the timer 2 interrupt
 //These pins are used to control the display
 pinMode(segA, OUTPUT);
 pinMode(segB, OUTPUT);
 pinMode(segC, OUTPUT);
 pinMode(segD, OUTPUT);
 pinMode(segE, OUTPUT);
 pinMode(segF, OUTPUT);
 pinMode(segG, OUTPUT);
 pinMode(digit1, OUTPUT);
 pinMode(digit2, OUTPUT);
 pinMode(digit3, OUTPUT);
 pinMode(digit4, OUTPUT);
 pinMode(colons, OUTPUT);
 // setup PID stuff
 myPID.SetOutputLimits(PWM_MIN-1, PWM_MS-PWM_MIN+1);
 myPID.SetMode(AUTOMATIC);
 myPID.SetSampleTime(PWM_MS);
 windowStartTime = millis();
 // initialize pwm
 pwm_duty = 0; // off
 t_incub = read_temperature();
 t_incub_N = 1;
 // initialize slow variables for display
 t_incub_disp = t_incub;

}

void loop() {

 //displayLetters("UCOK");
 
 //temperatureControl();
 
 analogIn();
 
 displayNumber(a_Poti, FALSE); //Each call takes about 8ms, display the colon

}

// Simple PWM based on millis directly

void temperatureControl() {

 unsigned long now = millis();
 // averaging over the whole 5 seconds
 t_incub += (read_temperature() - t_incub)/(++t_incub_N);
 if(now - windowStartTime > PWM_MS)
 { 
   // compute new pwm value for that window
   if (t_set != 0)
     myPID.Compute();
   // start a new relay window
   windowStartTime = now;
   // restart averaging of temperature
   t_incub_disp = t_incub;
   t_incub = read_temperature();
   t_incub_N = 1;
 }


}

void analogIn() {

 a_Poti = read_AnalogIn();
   

}

float read_temperature() {

 float A = 0;
 for (int i=0 ; i < 10 ; i++)
   A += analogRead(temp_sen);
 A /= 10;
 return (A/1023.*3300 - 600)/10;

}

float read_AnalogIn() {

 float A = 0;
 for (int i=0 ; i < 100 ; i++)
   A += analogRead(poti_sen);
 A /= 100;
 return (A);

}

</syntaxhighlight>

dusjagr's freq-measurement

Adding an oscillator 4093 circuit and measuring the frequency with the arduino, display the count on the 4-digit

<syntaxhighlight lang="c">


/*

* (c) Fakufaku 2013
* This is the code for the homebrew incubator 'Fermento'
* This code is released under the CC-BY-SA 3.0 License.
* The part of the code that's used for the display on the 7-segment was ripped off the BigTime code from Nathan Seidl. I owe him a beer then.
*/
  1. include <math.h>
  1. include <PID_v1.h>
  1. define TRUE 1
  2. define FALSE 0

//Careful messing with the system color, you can damage the display if //you assign the wrong color. If you're in doubt, set it to red and load the code, //then see what the color is.

  1. define RED 1
  2. define GREEN 2
  3. define BLUE 3
  4. define YELLOW 4

int systemColor = RED; int display_brightness = 15000; //A larger number makes the display more dim. This is set correctly below. // slow continuous PWM variables

  1. define PWM_MS 50 // this changes the update speed
  2. define PWM_MIN 100
  3. define RELAY_ON LOW
  4. define RELAY_OFF HIGH

// PID loop parameter

  1. define PID_KP 50
  2. define PID_KI 1
  3. define PID_KD 1

// Some display related parameters (time in seconds, temperature in degrees Celsius)

  1. define TIME_INCREMENT 1800
  2. define MAX_TIME 356459
  3. define TEMP_INCREMENT 1
  4. define MAX_TEMP 65

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Uncomment following line for the homebrew (1-sided) PCB version //#define FERMENTO_1SIDE

  1. define FERMENTO_DUSJAGR

//Pin definitions

  1. ifdef FERMENTO_DUSJAGR

int digit1 = 13; //Display pin 12 int digit2 = 10; //Display pin 9 int digit3 = 9; //Display pin 8 int digit4 = 7; //Display pin 6

int segA = 12; //Display pin 11 int segB = 8; //Display pin 7 int segC = 5; //Display pin 4 int segD = 3; //Display pin 2 int segE = 2; //Display pin 1 int segF = 11; //Display pin 10 int segG = 6; //Display pin 5

int colons = 4; //Display pin 3

int temp_sen = A5; // to read the temperature sensor int poti_sen = A4; // to read the temperature sensor

int pinInt = A5;

uint8_t input = 0; uint8_t inputNext = 0;

uint16_t count = 0; uint16_t countTMP = 0;

uint8_t countHB = 0; uint8_t countLB = 0; uint16_t countSQ = 0;

int averaging = 1;

const static int buzz = A2; const static int theButton = A1; const static int theButton2 = A0; const static int pwm_pin = A3; // Pin 4

// The interrupt of button1 is on external interrupt 0 // The interrupt of button2 is on external interrupt 1

  1. define BUTTON1_INT_VECT INT0_vect
  2. define BUTTON2_INT_VECT INT1_vect
  3. define BUTTONS_INT_SET() do \
 {                           \
   EICRA = (1<<ISC11) + (1<<ISC01); /* falling edge */ \
   EIMSK = (1<<INT1) + (1<<INT0);      \
 }                           \
 while (0)
  1. else

// The interrupt of button1 is on external interrupt 0 // The interrupt of button2 is on PCINT13 (A5), on PCIE1.

  1. define BUTTON1_INT_VECT INT0_vect
  2. define BUTTON2_INT_VECT PCINT1_vect
  3. define BUTTONS_INT_SET() do \
 {                           \
   EICRA = (1<<ISC01); /* falling edge */     \
   EIMSK = (1<<INT0);        \
   PCICR = (1 << PCIE1);     \
   PCMSK1 = (1 << PCINT13);  \
 }                           \
 while (0)
  1. endif

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


// Display status variable

  1. define TIME 1
  2. define TEMP 2

int display_status = TEMP; int backoff = 0; // just a short backoff for when we switch the display between TIME/TEMP

  1. define BACKOFFTIME 2

char disp_str[4];

// Variable to keep track of PWM window unsigned long windowStartTime;

// control variables for PID double t_incub; // input to PID (temperature in incubator) double t_incub_N; // number of samples in t_incub average double pwm_duty; // output of PID double t_set = 0; // set point (target temperature) double a_Poti; // poti value

//Specify the links and initial tuning parameters PID myPID(&t_incub, &pwm_duty, &t_set, PID_KP, PID_KI, PID_KD, DIRECT);

// display timer (freeze parameters to display for 2 seconds) int t_incub_disp;

// Timer variables unsigned long timer_seconds = 0;

//The very important 32.686kHz interrupt handler SIGNAL(TIMER2_OVF_vect) {

 if (timer_seconds > 1)
 {
   timer_seconds--;
 }
 else if (timer_seconds == 1)
 {
   // reset timer
   timer_seconds = 0;
   // turn off by setting target temperature to zero
   t_set = 0;
   // Reset the PID
   myPID.SetMode(MANUAL);
   myPID.SetMode(AUTOMATIC);
 }
 // decrement backoff
 if (backoff > 0)
   backoff--;

}

//The interrupt occurs when you push the button SIGNAL(BUTTON1_INT_VECT) {

 display_status = TEMP;
 backoff = BACKOFFTIME;

}

SIGNAL(BUTTON2_INT_VECT) {

 display_status = TIME;
 backoff = BACKOFFTIME;

}

void setup() {

 Serial.begin(9600);
 // set ADC reference to 3.3V
 analogReference(DEFAULT);
 // initialize pwm drive pin, and turn it off
 pinMode(pwm_pin, OUTPUT);
 digitalWrite(pwm_pin, HIGH);
 // initialize buzzer pin
 pinMode(buzz, OUTPUT);
 // initialize the buttons
 pinMode(theButton, INPUT);
 digitalWrite(theButton, HIGH); // pull-up
 pinMode(theButton2, INPUT);
 digitalWrite(theButton2, HIGH); // pull-up
 BUTTONS_INT_SET();
 //Setup TIMER2
 TCCR2A = 0x00;
 TCCR2B = (1<<CS22)|(1<<CS20); //Set CLK/128 or overflow interrupt every 1s
 ASSR   = (1<<AS2); //Enable asynchronous operation
 TIMSK2 = (1<<TOIE2); //Enable the timer 2 interrupt
 //These pins are used to control the display
 pinMode(segA, OUTPUT);
 pinMode(segB, OUTPUT);
 pinMode(segC, OUTPUT);
 pinMode(segD, OUTPUT);
 pinMode(segE, OUTPUT);
 pinMode(segF, OUTPUT);
 pinMode(segG, OUTPUT);
 pinMode(digit1, OUTPUT);
 pinMode(digit2, OUTPUT);
 pinMode(digit3, OUTPUT);
 pinMode(digit4, OUTPUT);
 pinMode(colons, OUTPUT);
 pinMode(pinInt, INPUT);
 // setup PID stuff
 myPID.SetOutputLimits(PWM_MIN-1, PWM_MS-PWM_MIN+1);
 myPID.SetMode(AUTOMATIC);
 myPID.SetSampleTime(PWM_MS);
 windowStartTime = millis();
 // initialize pwm
 pwm_duty = 0; // off
 t_incub = read_temperature();
 t_incub_N = 1;
 // initialize slow variables for display
 t_incub_disp = t_incub;

}

void loop() {

 getFreq();
   
 for(int c = 0 ; c < 1; c +=1) { 
 displayNumber(count, FALSE); //Each call takes about 8ms, display the colon
 }
 /*
 Serial.print("sensor = " );                       
 Serial.print(count);      
 Serial.print("\t output = ");      
 Serial.println(countSQ);  
 */

}

// Simple PWM based on millis directly

void temperatureControl() {

 unsigned long now = millis();
 // averaging over the whole 5 seconds
 t_incub += (read_temperature() - t_incub)/(++t_incub_N);
 if(now - windowStartTime > PWM_MS)
 { 
   // compute new pwm value for that window
   if (t_set != 0)
     myPID.Compute();
   // start a new relay window
   windowStartTime = now;
   // restart averaging of temperature
   t_incub_disp = t_incub;
   t_incub = read_temperature();
   t_incub_N = 1;
 }


}

void analogIn() {

 a_Poti = read_AnalogIn();
   

}

void getFreq() {

 countTMP = 0;
 count = 0;

 for(int c = 0 ; c < averaging; c +=1) { 

   countTMP = 0; 

   input = digitalRead(pinInt);

   for (int16_t i = 0; i < 3000; i++){

     inputNext = digitalRead(pinInt);

     if(input != inputNext){
       countTMP = countTMP + 1;
       input=inputNext;
     }
   }

   count = count + countTMP;

 }

 count = count / averaging;
   

}

</syntaxhighlight>

* Routines to display on 7-segment *

<syntaxhighlight lang="c">


/************************************/ /* Routines to display on 7-segment */ /************************************/

//Given 1022, we display "10:22" //Each digit is displayed for ~2000us, and cycles through the 4 digits //After running through the 4 numbers, the display is turned off

void displayNumber(int toDisplay, boolean displayColon) {

  1. define DIGIT_ON LOW
  2. define DIGIT_OFF HIGH
 for(int digit = 4 ; digit > 0 ; digit--) {
   //Turn on a digit for a short amount of time
   switch(digit) {
   case 1:
     digitalWrite(digit1, DIGIT_ON);
     digitalWrite(colons, LOW);
     break;
   case 2:
     digitalWrite(digit2, DIGIT_ON);
     digitalWrite(colons, LOW);
     break;
   case 3:
     digitalWrite(digit3, DIGIT_ON);
     if(displayColon == TRUE) 
       digitalWrite(colons, HIGH); //When we update digit 2, let's turn on colons as well
     else
       digitalWrite(colons, LOW);
     break;
   case 4:
     digitalWrite(digit4, DIGIT_ON);
     digitalWrite(colons, LOW);
     break;
   }
   //Now display this digit
   if (digit != 5)
   {
     if( (toDisplay/10 != 0) || (toDisplay % 10) != 0) // do not display leading zeros
       lightNumber(toDisplay % 10); //Turn on the right segments for this digit
       toDisplay /= 10;
   }
   else
   {
    // lightNumber(0);
   }
   
   delayMicroseconds(2000); //Display this digit for a fraction of a second (between 1us and 5000us, 500-2000 is pretty good)
   //If you set this too long, the display will start to flicker. Set it to 25000 for some fun.
   //Turn off all segments
   lightNumber(10);
   //Turn off all digits
   digitalWrite(digit1, DIGIT_OFF);
   digitalWrite(digit2, DIGIT_OFF);
   digitalWrite(digit3, DIGIT_OFF);
   digitalWrite(digit4, DIGIT_OFF);
   digitalWrite(colons, DIGIT_OFF);
   //digitalWrite(ampm, DIGIT_OFF);
 }

}

//Takes a string like "gren" and displays it, left justified //We don't use the colons, or AMPM dot, so they are turned off void displayLetters(char * colorName) {

  1. define DIGIT_ON HIGH
  2. define DIGIT_OFF LOW
 digitalWrite(digit4, DIGIT_ON);
 digitalWrite(colons, DIGIT_OFF);
 //digitalWrite(ampm, DIGIT_OFF);
 for(int digit = 0 ; digit < 4 ; digit++) {
   //Turn on a digit for a short amount of time
   switch(digit) {
   case 0:
     digitalWrite(digit1, DIGIT_ON);
     break;
   case 1:
     digitalWrite(digit2, DIGIT_ON);
     break;
   case 2:
     digitalWrite(digit3, DIGIT_ON);
     break;
   case 3:
     digitalWrite(digit4, DIGIT_ON);
     break;
   }
   //Now display this letter
   lightNumber(colorName[digit]); //Turn on the right segments for this letter
   delayMicroseconds(2000); //Display this digit for a fraction of a second (between 1us and 5000us, 500-2000 is pretty good)
   //If you set this too long, the display will start to flicker. Set it to 25000 for some fun.
   //Turn off all segments
   lightNumber(10);
   //Turn off all digits
   digitalWrite(digit1, DIGIT_OFF);
   digitalWrite(digit2, DIGIT_OFF);
   digitalWrite(digit3, DIGIT_OFF);
   digitalWrite(digit4, DIGIT_OFF);
 }

}

//Given a number, turns on those segments //If number == 10, then turn off all segments void lightNumber(int numberToDisplay) {

  1. define SEGMENT_ON HIGH
  2. define SEGMENT_OFF LOW
 /*

Segments

  -  A
  F / / B
  -  G
  E / / C
  -  D
  */
 switch (numberToDisplay)
 {
 case 0:
   digitalWrite(segA, SEGMENT_ON);
   digitalWrite(segB, SEGMENT_ON);
   digitalWrite(segC, SEGMENT_ON);
   digitalWrite(segD, SEGMENT_ON);
   digitalWrite(segE, SEGMENT_ON);
   digitalWrite(segF, SEGMENT_ON);
   break;
 case 1:
   digitalWrite(segB, SEGMENT_ON);
   digitalWrite(segC, SEGMENT_ON);
   break;
 case 2:
   digitalWrite(segA, SEGMENT_ON);
   digitalWrite(segB, SEGMENT_ON);
   digitalWrite(segD, SEGMENT_ON);
   digitalWrite(segE, SEGMENT_ON);
   digitalWrite(segG, SEGMENT_ON);
   break;
 case 3:
   digitalWrite(segA, SEGMENT_ON);
   digitalWrite(segB, SEGMENT_ON);
   digitalWrite(segC, SEGMENT_ON);
   digitalWrite(segD, SEGMENT_ON);
   digitalWrite(segG, SEGMENT_ON);
   break;
 case 4:
   digitalWrite(segB, SEGMENT_ON);
   digitalWrite(segC, SEGMENT_ON);
   digitalWrite(segF, SEGMENT_ON);
   digitalWrite(segG, SEGMENT_ON);
   break;
 case 5:
   digitalWrite(segA, SEGMENT_ON);
   digitalWrite(segC, SEGMENT_ON);
   digitalWrite(segD, SEGMENT_ON);
   digitalWrite(segF, SEGMENT_ON);
   digitalWrite(segG, SEGMENT_ON);
   break;
 case 6:
   digitalWrite(segA, SEGMENT_ON);
   digitalWrite(segC, SEGMENT_ON);
   digitalWrite(segD, SEGMENT_ON);
   digitalWrite(segE, SEGMENT_ON);
   digitalWrite(segF, SEGMENT_ON);
   digitalWrite(segG, SEGMENT_ON);
   break;
 case 7:
   digitalWrite(segA, SEGMENT_ON);
   digitalWrite(segB, SEGMENT_ON);
   digitalWrite(segC, SEGMENT_ON);
   break;
 case 8:
   digitalWrite(segA, SEGMENT_ON);
   digitalWrite(segB, SEGMENT_ON);
   digitalWrite(segC, SEGMENT_ON);
   digitalWrite(segD, SEGMENT_ON);
   digitalWrite(segE, SEGMENT_ON);
   digitalWrite(segF, SEGMENT_ON);
   digitalWrite(segG, SEGMENT_ON);
   break;
 case 9:
   digitalWrite(segA, SEGMENT_ON);
   digitalWrite(segB, SEGMENT_ON);
   digitalWrite(segC, SEGMENT_ON);
   digitalWrite(segD, SEGMENT_ON);
   digitalWrite(segF, SEGMENT_ON);
   digitalWrite(segG, SEGMENT_ON);
   break;
 case 10:
   digitalWrite(segA, SEGMENT_OFF);
   digitalWrite(segB, SEGMENT_OFF);
   digitalWrite(segC, SEGMENT_OFF);
   digitalWrite(segD, SEGMENT_OFF);
   digitalWrite(segE, SEGMENT_OFF);
   digitalWrite(segF, SEGMENT_OFF);
   digitalWrite(segG, SEGMENT_OFF);
   break;
   /*

Segments

    -  A
    F / / B
    -    G
    E / / C
    - D
    */
   //Letters
 case 'b': //cdefg
   digitalWrite(segC, SEGMENT_ON);
   digitalWrite(segD, SEGMENT_ON);
   digitalWrite(segE, SEGMENT_ON);
   digitalWrite(segF, SEGMENT_ON);
   digitalWrite(segG, SEGMENT_ON);
   break;
 case 'L': //def
   digitalWrite(segD, SEGMENT_ON);
   digitalWrite(segE, SEGMENT_ON);
   digitalWrite(segF, SEGMENT_ON);
   break;
 case 'u': //cde
   digitalWrite(segC, SEGMENT_ON);
   digitalWrite(segD, SEGMENT_ON);
   digitalWrite(segE, SEGMENT_ON);
   break;
 case 'g': //abcdfg
   digitalWrite(segA, SEGMENT_ON);
   digitalWrite(segB, SEGMENT_ON);
   digitalWrite(segC, SEGMENT_ON);
   digitalWrite(segD, SEGMENT_ON);
   digitalWrite(segF, SEGMENT_ON);
   digitalWrite(segG, SEGMENT_ON);
   break;
 case 'r': //eg
   digitalWrite(segE, SEGMENT_ON);
   digitalWrite(segG, SEGMENT_ON);
   break;
 case 'n': //ceg
   digitalWrite(segC, SEGMENT_ON);
   digitalWrite(segE, SEGMENT_ON);
   digitalWrite(segG, SEGMENT_ON);
   break;
   //case r
 case 'e': //adefg
   digitalWrite(segA, SEGMENT_ON);
   digitalWrite(segD, SEGMENT_ON);
   digitalWrite(segE, SEGMENT_ON);
   digitalWrite(segF, SEGMENT_ON);
   digitalWrite(segG, SEGMENT_ON);
   break;
 case 'd': //bcdeg
   digitalWrite(segB, SEGMENT_ON);
   digitalWrite(segC, SEGMENT_ON);
   digitalWrite(segD, SEGMENT_ON);
   digitalWrite(segE, SEGMENT_ON);
   digitalWrite(segG, SEGMENT_ON);
   break;
 case ' ': //None
   digitalWrite(segA, SEGMENT_OFF);
   digitalWrite(segB, SEGMENT_OFF);
   digitalWrite(segC, SEGMENT_OFF);
   digitalWrite(segD, SEGMENT_OFF);
   digitalWrite(segE, SEGMENT_OFF);
   digitalWrite(segF, SEGMENT_OFF);
   digitalWrite(segG, SEGMENT_OFF);
   break;
 case 'y': //bcdfg
   digitalWrite(segB, SEGMENT_ON);
   digitalWrite(segC, SEGMENT_ON);
   digitalWrite(segD, SEGMENT_ON);
   digitalWrite(segF, SEGMENT_ON);
   digitalWrite(segG, SEGMENT_ON);
   break;
   
 case 'U': //bcdfg
   digitalWrite(segB, SEGMENT_ON);
   digitalWrite(segC, SEGMENT_ON);
   digitalWrite(segD, SEGMENT_ON);
   digitalWrite(segE, SEGMENT_ON);
   digitalWrite(segF, SEGMENT_ON);
   break;
   
 case 'C': //bcdfg
   digitalWrite(segA, SEGMENT_ON);
   digitalWrite(segD, SEGMENT_ON);
   digitalWrite(segE, SEGMENT_ON);
   digitalWrite(segF, SEGMENT_ON);
   break;
   
 case 'O': //bcdfg
   digitalWrite(segA, SEGMENT_ON);
   digitalWrite(segB, SEGMENT_ON);
   digitalWrite(segC, SEGMENT_ON);
   digitalWrite(segD, SEGMENT_ON);
   digitalWrite(segE, SEGMENT_ON);
   digitalWrite(segF, SEGMENT_ON);
   break;
   
 case 'K': //bcdfg
   digitalWrite(segB, SEGMENT_ON);
   digitalWrite(segC, SEGMENT_ON);
   digitalWrite(segE, SEGMENT_ON);
   digitalWrite(segF, SEGMENT_ON);
   digitalWrite(segG, SEGMENT_ON);
   break;
 
   
   //case e 
   //case L
 case 'o': //cdeg
   digitalWrite(segC, SEGMENT_ON);
   digitalWrite(segD, SEGMENT_ON);
   digitalWrite(segE, SEGMENT_ON);
   digitalWrite(segG, SEGMENT_ON);
   break;
 case 'º': // abfg
   digitalWrite(segA, SEGMENT_ON);
   digitalWrite(segB, SEGMENT_ON);
   digitalWrite(segF, SEGMENT_ON);
   digitalWrite(segG, SEGMENT_ON);
   break;
 }

}

</syntaxhighlight>