xockcin
Published © GPL3+

Hex Machine

A simple gadget that translates binary numbers into hexadecimal.

BeginnerShowcase (no instructions)395
Hex Machine

Things used in this project

Hardware components

7 Segment LED Display, InfoVue
7 Segment LED Display, InfoVue
I used the common cathode 7-segment display that comes with the ELEGOO Arduino starter kit.
×1
Tactile Switch, Top Actuated
Tactile Switch, Top Actuated
×4
LED (generic)
LED (generic)
×4
Resistor 330 ohm
Resistor 330 ohm
×11
Breadboard (generic)
Breadboard (generic)
×1

Story

Read more

Schematics

hexmachine_Bs1NkGSIkP.fzz

hexmachine_schem_ORf9OixD1y.png

Code

hexMachine

Arduino
This is the cool part!
// this program takes a combination of four different buttons as an input, and outputs the corresponding hex digit as an output.

// pins for the four buttons
int buttons[4] = {A3,A2,A1,A0};
// pins for the seven segments.
// you might have to adjust this line
// if you are using something other
// than the adafruit trinket.
int light[7] = {0,1,3,4,5,6,8};
// configurations for the sixteen digits.
// see the hand-drawn charts above for details.
int digits[16] = {0x3F, 0x9, 0x5E, 0x5B, 0x69, 0x73, 0x77, 0x19, 0x7F, 0x7B, 0x7D, 0x67, 0x36, 0x4F, 0x76, 0x74};
// variable for button state
int state = 0;

void setup() {
  
  // initialize button pins
  for (int i=0;i<4;i++) {
    pinMode(buttons[i], INPUT);
  }
  // initialize display pins
  for (int i=0;i<7;i++) {
    pinMode(light[i], OUTPUT);
  }
}
  
void loop() {
  
  //initialize number to zero
  int number = 0;
  
  //read buttons
  for (int i=0;i<4;i++) {               // for each button...
    state = digitalRead(buttons[i]);    // find out if it's pressed or not.
    if (state == HIGH) {                // if it's pressed...
      number += 1<<i;                   // add 2^i to the number.
    }
  }
  
  //display number
  for (int i=0;i<7;i++) {               // for each segment...
    if (digits[number] & 1<<i) {        // if the number requires that segment...
      digitalWrite(light[i], HIGH);     // light up the segment!
    }
    else {                              // otherwise...
      digitalWrite(light[i], LOW);      // don't light up that segment.
    }
  }
}

Credits

xockcin

xockcin

0 projects • 0 followers

Comments