Decimal to Binary Converter using 4x4 Keypad
This project shows how to convert a Decimal number into a Binary number with Arduino Mega.
Components and supplies
1
4x4 Keypad
1
Jumper wires (generic)
8
LED (generic)
1
OLED Display (I2C)
1
Arduino Mega 2560
1
Breadboard (generic)
Apps and platforms
1
Arduino IDE
Project description
Code
Code
arduino
1/* 2 3 This sketch converts a Decimal number into a Binary number. 4 The Decimal number is fed to the Arduino through a 4x4 Keypad. 5 A function then converts this Decimal number to its Binary 6 equivalent. These numbers are displayed on an OLED Display and Serial Monitor. 7 The Binary number is also represented with 8 LEDs. 8 9 This program is made by Shreyas for Electronics Champ YouTube Channel. 10 Please subscribe to this channel. Thank You. 11 12*/ 13 14 15//Including the libraries 16#include <Keypad.h> 17#include <Wire.h> 18#include <Adafruit_GFX.h> 19#include <Adafruit_SSD1306.h> 20 21#define SCREEN_WIDTH 128 22#define SCREEN_HEIGHT 64 23 24const byte ROWS = 4; //Four rows of Keypad 25const byte COLS = 4; //Four columns of Keypad 26char key = ""; 27String decimalNum; 28long decimalNumber; 29long binaryNumber; 30String stringBinary = ""; 31 32//Define the symbols on the buttons of the keypad 33char Keys[ROWS][COLS] = { 34 35 {'1', '2', '3', 'A'}, 36 {'4', '5', '6', 'B'}, 37 {'7', '8', '9', 'C'}, 38 {'*', '0', '#', 'D'} 39 40}; 41 42byte rowPins[ROWS] = {2, 3, 4, 5}; 43byte colPins[COLS] = {6, 7, 8, 9}; 44Keypad myKeypad = Keypad(makeKeymap(Keys), rowPins, colPins, ROWS, COLS); 45Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT); 46 47//Prints the EChamp logo on OLED Display 48static const uint8_t PROGMEM logo[] = { 49 50 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 51 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 52 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 53 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 54 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 55 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 56 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 57 0x00, 0x00, 0x07, 0xe8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 58 0x00, 0x00, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 59 0x00, 0x01, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 60 0x00, 0x07, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 61 0x00, 0x1f, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 62 0x00, 0x7f, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 63 0x00, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 64 0x01, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 65 0x03, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 66 0x07, 0xfc, 0x11, 0xf1, 0x0f, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 67 0x0f, 0xfc, 0xf1, 0xf1, 0xe7, 0xfe, 0x00, 0x7e, 0x60, 0x00, 0x30, 0x00, 0x00, 0x30, 0x00, 0x00, 68 0x1f, 0xfd, 0xfb, 0xf3, 0xe7, 0xff, 0x00, 0x60, 0x60, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 69 0x1f, 0xfd, 0xff, 0xff, 0xe7, 0xff, 0x00, 0x60, 0x63, 0x87, 0xbb, 0xc7, 0x1f, 0x33, 0xcf, 0x00, 70 0x3f, 0xfd, 0xff, 0xff, 0xe7, 0xff, 0x80, 0x60, 0x66, 0xcd, 0xb3, 0x4d, 0x9b, 0x36, 0xdb, 0x00, 71 0x3f, 0xfd, 0xf9, 0xf3, 0xe7, 0xff, 0x80, 0x7e, 0x64, 0x48, 0x33, 0x08, 0x99, 0x34, 0x18, 0x00, 72 0x7e, 0x40, 0x11, 0xf1, 0x20, 0x1f, 0xc0, 0x60, 0x67, 0xc8, 0x33, 0x08, 0x99, 0x34, 0x1f, 0x00, 73 0x7e, 0x7d, 0xf9, 0xf3, 0xe7, 0xdf, 0xc0, 0x60, 0x64, 0x08, 0x33, 0x08, 0x99, 0x34, 0x01, 0x00, 74 0x7e, 0x7d, 0xfb, 0xff, 0xe7, 0xdf, 0xc0, 0x60, 0x66, 0xcd, 0xb3, 0x0d, 0x99, 0x36, 0xdb, 0x00, 75 0x7e, 0x7d, 0xff, 0xff, 0xe7, 0xdf, 0xc0, 0x7e, 0x63, 0xc7, 0xbb, 0x07, 0x19, 0x33, 0xde, 0x00, 76 0x7e, 0x7d, 0xf9, 0xf3, 0xe7, 0xdf, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 77 0xfe, 0x7c, 0xf1, 0xf1, 0x67, 0xdf, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 78 0xfe, 0x7e, 0x11, 0xf1, 0x0f, 0xdf, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 79 0xfe, 0x7f, 0xfb, 0xf3, 0xff, 0xdf, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 80 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xdf, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 81 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xdf, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 82 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xdf, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 83 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xdf, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 84 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xdf, 0xe0, 0x3c, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 85 0x7e, 0x7f, 0xff, 0xff, 0x7f, 0xdf, 0xe0, 0x7e, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 86 0x7e, 0x7f, 0x27, 0xf8, 0x9f, 0xdf, 0xc0, 0x62, 0x7c, 0x71, 0xf7, 0x3e, 0x00, 0x00, 0x00, 0x00, 87 0x7e, 0x7e, 0xf1, 0xe1, 0xcf, 0xdf, 0xc0, 0x60, 0x6c, 0x59, 0xbb, 0x36, 0x00, 0x00, 0x00, 0x00, 88 0x7e, 0x7e, 0xf8, 0xe3, 0xef, 0xdf, 0xc0, 0x60, 0x64, 0x09, 0x91, 0x32, 0x00, 0x00, 0x00, 0x00, 89 0x3e, 0x7c, 0xf9, 0xf3, 0xef, 0xdf, 0x80, 0x60, 0x64, 0xf9, 0x91, 0x32, 0x00, 0x00, 0x00, 0x00, 90 0x3f, 0x01, 0xff, 0xff, 0xe0, 0x1f, 0x80, 0x62, 0x64, 0x89, 0x91, 0x32, 0x00, 0x00, 0x00, 0x00, 91 0x1f, 0xfc, 0xf9, 0xf3, 0xef, 0xff, 0x80, 0x7e, 0x64, 0x99, 0x91, 0x36, 0x00, 0x00, 0x00, 0x00, 92 0x1f, 0xfe, 0xf8, 0xe3, 0xef, 0xff, 0x00, 0x3c, 0x64, 0xf9, 0x91, 0x3e, 0x00, 0x00, 0x00, 0x00, 93 0x0f, 0xfe, 0x71, 0xf1, 0xdf, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 94 0x0f, 0xff, 0x01, 0xfc, 0x3f, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 95 0x07, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 96 0x03, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 97 0x01, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 98 0x00, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 99 0x00, 0x7f, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 100 0x00, 0x1f, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 101 0x00, 0x07, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 102 0x00, 0x00, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 103 0x00, 0x00, 0x7f, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 104 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 105 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 106 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 107 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 108 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 109 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 110 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 111 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 112 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 113 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 114 115}; 116 117void setup() { 118 119 Serial.begin(9600); 120 oled.begin(SSD1306_SWITCHCAPVCC, 0x3C); 121 oled.clearDisplay(); 122 123 //Prints the logo on OLED Display 124 oled.drawBitmap(0, 0, logo, 128, 64, 1); 125 oled.display(); 126 delay(3000); 127 oled.clearDisplay(); 128 129 oled.setTextSize(2); 130 oled.setTextColor(WHITE); 131 oled.setCursor(5, 10); 132 oled.print("D:"); 133 oled.println('0'); 134 oled.setTextSize(2); 135 oled.setTextColor(WHITE); 136 oled.setCursor(5, 40); 137 oled.print("B:"); 138 oled.println('0'); 139 oled.display(); 140 141 //Sets pins 30 to 37 as output for LEDs 142 for (int i = 30; i < 38; i++) { 143 144 pinMode(i, OUTPUT); 145 146 } 147 148} 149 150void loop() { 151 152 key = myKeypad.getKey(); 153 154 if (key) { 155 156 if (key != 'A' and key != 'B' and key != 'C' and key != 'D' and key != '*' and key != '#') { 157 158 decimalNum = decimalNum + String(key); 159 decimalNumber = decimalNum.toInt(); 160 161 if (decimalNumber <= 255) { 162 163 //Converts Decimal to Binary 164 binaryNumber = convertDecimalToBinary(decimalNumber); 165 stringBinary = String(binaryNumber); 166 167 //Prints the Binary and the Decimal numbers on the OLED Display 168 oled.clearDisplay(); 169 oled.setTextSize(2); 170 oled.setTextColor(WHITE); 171 oled.setCursor(5, 10); 172 oled.print("D:"); 173 oled.println(decimalNumber); 174 oled.setTextSize(2); 175 oled.setTextColor(WHITE); 176 oled.setCursor(5, 40); 177 oled.print("B:"); 178 oled.println(binaryNumber); 179 oled.display(); 180 181 //Prints the Decimal number on the Serial Monitor 182 Serial.print("Decimal: "); 183 Serial.print(decimalNumber); 184 Serial.print(" "); 185 186 //Prints the Binary number on the Serial Monitor 187 Serial.print("Binary: "); 188 Serial.println(binaryNumber); 189 190 //This function turns on the LEDs accordingly 191 LEDOutput(); 192 193 } 194 195 //If the decimal number is greater than 255... 196 else { 197 198 oled.clearDisplay(); 199 oled.setTextSize(2); 200 oled.setTextColor(WHITE); 201 oled.setCursor(5, 5); 202 oled.print("Max value"); 203 oled.setCursor(5, 25); 204 oled.print("allowed is"); 205 oled.setCursor(5, 45); 206 oled.print("255"); 207 oled.display(); 208 Serial.println("Max value allowed is 255"); 209 delay(1000); 210 211 } 212 213 } 214 215 //Clears the numbers 216 else if (key == 'C') { 217 218 decimalNum = ""; 219 decimalNumber = 0; 220 oled.clearDisplay(); 221 oled.setTextSize(2); 222 oled.setTextColor(WHITE); 223 oled.setCursor(5, 10); 224 oled.print("D:"); 225 oled.println('0'); 226 oled.setTextSize(2); 227 oled.setTextColor(WHITE); 228 oled.setCursor(5, 40); 229 oled.print("B:"); 230 oled.println('0'); 231 oled.display(); 232 233 for (int i = 30; i < 38; i++) { 234 235 digitalWrite(i, 0); 236 237 } 238 239 } 240 241 } 242 243} 244 245//This function converts a Decimal number to Binary number 246long convertDecimalToBinary(int number) { 247 248 int reminder; 249 String bin; 250 251 while (number) { 252 253 reminder = number % 2; 254 number = number / 2; 255 bin = String(reminder) + bin; 256 257 } 258 259 return bin.toInt(); 260 261} 262 263//This function turns on the LEDs accordingly 264void LEDOutput() { 265 266 int led = 30; 267 int eight_bitBinary; 268 269 if (stringBinary.length() != 8) { 270 271 eight_bitBinary = 8 - stringBinary.length(); 272 273 for (int i = 0; i < eight_bitBinary; i++) { 274 275 stringBinary = "0" + stringBinary; 276 277 } 278 279 } 280 281 for (int i = 0; i <= 8; i++) { 282 283 int ledState = stringBinary.substring(i, i + 1).toInt(); 284 digitalWrite(led, ledState); 285 led = led + 1; 286 287 } 288 289}
Code
arduino
1/* 2 3 This sketch converts a Decimal number into a Binary number. 4 5 The Decimal number is fed to the Arduino through a 4x4 Keypad. 6 A function 7 then converts this Decimal number to its Binary 8 equivalent. These numbers are 9 displayed on an OLED Display and Serial Monitor. 10 The Binary number is also 11 represented with 8 LEDs. 12 13 This program is made by Shreyas for Electronics 14 Champ YouTube Channel. 15 Please subscribe to this channel. Thank You. 16 17*/ 18 19 20//Including 21 the libraries 22#include <Keypad.h> 23#include <Wire.h> 24#include <Adafruit_GFX.h> 25#include 26 <Adafruit_SSD1306.h> 27 28#define SCREEN_WIDTH 128 29#define SCREEN_HEIGHT 64 30 31const 32 byte ROWS = 4; //Four rows of Keypad 33const byte COLS = 4; //Four columns of Keypad 34char 35 key = ""; 36String decimalNum; 37long decimalNumber; 38long binaryNumber; 39String 40 stringBinary = ""; 41 42//Define the symbols on the buttons of the keypad 43char 44 Keys[ROWS][COLS] = { 45 46 {'1', '2', '3', 'A'}, 47 {'4', '5', '6', 'B'}, 48 49 {'7', '8', '9', 'C'}, 50 {'*', '0', '#', 'D'} 51 52}; 53 54byte rowPins[ROWS] 55 = {2, 3, 4, 5}; 56byte colPins[COLS] = {6, 7, 8, 9}; 57Keypad myKeypad = Keypad(makeKeymap(Keys), 58 rowPins, colPins, ROWS, COLS); 59Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT); 60 61//Prints 62 the EChamp logo on OLED Display 63static const uint8_t PROGMEM logo[] = { 64 65 66 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 67 0x00, 0x00, 0x00, 68 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 69 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 70 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 71 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 72 0x00, 0x00, 0x00, 0x00, 73 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 74 0x00, 75 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 76 0x00, 77 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 78 0x00, 0x00, 0x00, 0x00, 79 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 80 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 81 0x00, 0x00, 0x07, 0xe8, 0x00, 0x00, 82 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 83 0x00, 0x00, 0xff, 84 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 85 86 0x00, 0x01, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 87 0x00, 0x00, 0x00, 88 0x00, 0x07, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 89 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 90 0x00, 0x1f, 0xff, 0xff, 0xff, 0x00, 0x00, 91 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 92 0x00, 0x7f, 0xff, 0xff, 93 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 94 0x00, 95 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 96 0x00, 97 0x01, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 98 0x00, 0x00, 0x00, 0x00, 99 0x03, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 100 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 101 0x07, 0xfc, 0x11, 0xf1, 0x0f, 0xfc, 102 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 103 0x0f, 0xfc, 0xf1, 104 0xf1, 0xe7, 0xfe, 0x00, 0x7e, 0x60, 0x00, 0x30, 0x00, 0x00, 0x30, 0x00, 0x00, 105 106 0x1f, 0xfd, 0xfb, 0xf3, 0xe7, 0xff, 0x00, 0x60, 0x60, 0x00, 0x30, 0x00, 0x00, 107 0x00, 0x00, 0x00, 108 0x1f, 0xfd, 0xff, 0xff, 0xe7, 0xff, 0x00, 0x60, 0x63, 0x87, 109 0xbb, 0xc7, 0x1f, 0x33, 0xcf, 0x00, 110 0x3f, 0xfd, 0xff, 0xff, 0xe7, 0xff, 0x80, 111 0x60, 0x66, 0xcd, 0xb3, 0x4d, 0x9b, 0x36, 0xdb, 0x00, 112 0x3f, 0xfd, 0xf9, 0xf3, 113 0xe7, 0xff, 0x80, 0x7e, 0x64, 0x48, 0x33, 0x08, 0x99, 0x34, 0x18, 0x00, 114 0x7e, 115 0x40, 0x11, 0xf1, 0x20, 0x1f, 0xc0, 0x60, 0x67, 0xc8, 0x33, 0x08, 0x99, 0x34, 0x1f, 116 0x00, 117 0x7e, 0x7d, 0xf9, 0xf3, 0xe7, 0xdf, 0xc0, 0x60, 0x64, 0x08, 0x33, 0x08, 118 0x99, 0x34, 0x01, 0x00, 119 0x7e, 0x7d, 0xfb, 0xff, 0xe7, 0xdf, 0xc0, 0x60, 0x66, 120 0xcd, 0xb3, 0x0d, 0x99, 0x36, 0xdb, 0x00, 121 0x7e, 0x7d, 0xff, 0xff, 0xe7, 0xdf, 122 0xc0, 0x7e, 0x63, 0xc7, 0xbb, 0x07, 0x19, 0x33, 0xde, 0x00, 123 0x7e, 0x7d, 0xf9, 124 0xf3, 0xe7, 0xdf, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 125 126 0xfe, 0x7c, 0xf1, 0xf1, 0x67, 0xdf, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 127 0x00, 0x00, 0x00, 128 0xfe, 0x7e, 0x11, 0xf1, 0x0f, 0xdf, 0xe0, 0x00, 0x00, 0x00, 129 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 130 0xfe, 0x7f, 0xfb, 0xf3, 0xff, 0xdf, 0xe0, 131 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 132 0xfe, 0x7f, 0xff, 0xff, 133 0xff, 0xdf, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 134 0xfe, 135 0x7f, 0xff, 0xff, 0xff, 0xdf, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 136 0x00, 137 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xdf, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 138 0x00, 0x00, 0x00, 0x00, 139 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xdf, 0xe0, 0x00, 0x00, 140 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 141 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xdf, 142 0xe0, 0x3c, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 143 0x7e, 0x7f, 0xff, 144 0xff, 0x7f, 0xdf, 0xe0, 0x7e, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 145 146 0x7e, 0x7f, 0x27, 0xf8, 0x9f, 0xdf, 0xc0, 0x62, 0x7c, 0x71, 0xf7, 0x3e, 0x00, 147 0x00, 0x00, 0x00, 148 0x7e, 0x7e, 0xf1, 0xe1, 0xcf, 0xdf, 0xc0, 0x60, 0x6c, 0x59, 149 0xbb, 0x36, 0x00, 0x00, 0x00, 0x00, 150 0x7e, 0x7e, 0xf8, 0xe3, 0xef, 0xdf, 0xc0, 151 0x60, 0x64, 0x09, 0x91, 0x32, 0x00, 0x00, 0x00, 0x00, 152 0x3e, 0x7c, 0xf9, 0xf3, 153 0xef, 0xdf, 0x80, 0x60, 0x64, 0xf9, 0x91, 0x32, 0x00, 0x00, 0x00, 0x00, 154 0x3f, 155 0x01, 0xff, 0xff, 0xe0, 0x1f, 0x80, 0x62, 0x64, 0x89, 0x91, 0x32, 0x00, 0x00, 0x00, 156 0x00, 157 0x1f, 0xfc, 0xf9, 0xf3, 0xef, 0xff, 0x80, 0x7e, 0x64, 0x99, 0x91, 0x36, 158 0x00, 0x00, 0x00, 0x00, 159 0x1f, 0xfe, 0xf8, 0xe3, 0xef, 0xff, 0x00, 0x3c, 0x64, 160 0xf9, 0x91, 0x3e, 0x00, 0x00, 0x00, 0x00, 161 0x0f, 0xfe, 0x71, 0xf1, 0xdf, 0xff, 162 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 163 0x0f, 0xff, 0x01, 164 0xfc, 0x3f, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 165 166 0x07, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 167 0x00, 0x00, 0x00, 168 0x03, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 169 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 170 0x01, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 171 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 172 0x00, 0xff, 0xff, 0xff, 173 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 174 0x00, 175 0x7f, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 176 0x00, 177 0x00, 0x1f, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 178 0x00, 0x00, 0x00, 0x00, 179 0x00, 0x07, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 180 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 181 0x00, 0x00, 0xff, 0xff, 0xe0, 0x00, 182 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 183 0x00, 0x00, 0x7f, 184 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 185 186 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 187 0x00, 0x00, 0x00, 188 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 189 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 190 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 191 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 192 0x00, 0x00, 0x00, 0x00, 193 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 194 0x00, 195 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 196 0x00, 197 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 198 0x00, 0x00, 0x00, 0x00, 199 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 200 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 201 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 202 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 203 0x00, 0x00, 0x00, 204 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 205 206 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 207 0x00, 0x00, 0x00 208 209}; 210 211void setup() { 212 213 Serial.begin(9600); 214 215 oled.begin(SSD1306_SWITCHCAPVCC, 0x3C); 216 oled.clearDisplay(); 217 218 //Prints 219 the logo on OLED Display 220 oled.drawBitmap(0, 0, logo, 128, 64, 1); 221 oled.display(); 222 223 delay(3000); 224 oled.clearDisplay(); 225 226 oled.setTextSize(2); 227 oled.setTextColor(WHITE); 228 229 oled.setCursor(5, 10); 230 oled.print("D:"); 231 oled.println('0'); 232 oled.setTextSize(2); 233 234 oled.setTextColor(WHITE); 235 oled.setCursor(5, 40); 236 oled.print("B:"); 237 238 oled.println('0'); 239 oled.display(); 240 241 //Sets pins 30 to 37 as output 242 for LEDs 243 for (int i = 30; i < 38; i++) { 244 245 pinMode(i, OUTPUT); 246 247 248 } 249 250} 251 252void loop() { 253 254 key = myKeypad.getKey(); 255 256 if 257 (key) { 258 259 if (key != 'A' and key != 'B' and key != 'C' and key != 'D' and 260 key != '*' and key != '#') { 261 262 decimalNum = decimalNum + String(key); 263 264 decimalNumber = decimalNum.toInt(); 265 266 if (decimalNumber <= 255) 267 { 268 269 //Converts Decimal to Binary 270 binaryNumber = convertDecimalToBinary(decimalNumber); 271 272 stringBinary = String(binaryNumber); 273 274 //Prints the Binary 275 and the Decimal numbers on the OLED Display 276 oled.clearDisplay(); 277 278 oled.setTextSize(2); 279 oled.setTextColor(WHITE); 280 oled.setCursor(5, 281 10); 282 oled.print("D:"); 283 oled.println(decimalNumber); 284 285 oled.setTextSize(2); 286 oled.setTextColor(WHITE); 287 oled.setCursor(5, 288 40); 289 oled.print("B:"); 290 oled.println(binaryNumber); 291 oled.display(); 292 293 294 //Prints the Decimal number on the Serial Monitor 295 Serial.print("Decimal: 296 "); 297 Serial.print(decimalNumber); 298 Serial.print(" "); 299 300 301 //Prints the Binary number on the Serial Monitor 302 Serial.print("Binary: 303 "); 304 Serial.println(binaryNumber); 305 306 //This function turns 307 on the LEDs accordingly 308 LEDOutput(); 309 310 } 311 312 //If 313 the decimal number is greater than 255... 314 else { 315 316 oled.clearDisplay(); 317 318 oled.setTextSize(2); 319 oled.setTextColor(WHITE); 320 oled.setCursor(5, 321 5); 322 oled.print("Max value"); 323 oled.setCursor(5, 25); 324 325 oled.print("allowed is"); 326 oled.setCursor(5, 45); 327 oled.print("255"); 328 329 oled.display(); 330 Serial.println("Max value allowed is 255"); 331 332 delay(1000); 333 334 } 335 336 } 337 338 //Clears the numbers 339 340 else if (key == 'C') { 341 342 decimalNum = ""; 343 decimalNumber 344 = 0; 345 oled.clearDisplay(); 346 oled.setTextSize(2); 347 oled.setTextColor(WHITE); 348 349 oled.setCursor(5, 10); 350 oled.print("D:"); 351 oled.println('0'); 352 353 oled.setTextSize(2); 354 oled.setTextColor(WHITE); 355 oled.setCursor(5, 356 40); 357 oled.print("B:"); 358 oled.println('0'); 359 oled.display(); 360 361 362 for (int i = 30; i < 38; i++) { 363 364 digitalWrite(i, 0); 365 366 367 } 368 369 } 370 371 } 372 373} 374 375//This function converts a Decimal 376 number to Binary number 377long convertDecimalToBinary(int number) { 378 379 int 380 reminder; 381 String bin; 382 383 while (number) { 384 385 reminder = number 386 % 2; 387 number = number / 2; 388 bin = String(reminder) + bin; 389 390 } 391 392 393 return bin.toInt(); 394 395} 396 397//This function turns on the LEDs accordingly 398void 399 LEDOutput() { 400 401 int led = 30; 402 int eight_bitBinary; 403 404 if (stringBinary.length() 405 != 8) { 406 407 eight_bitBinary = 8 - stringBinary.length(); 408 409 for (int 410 i = 0; i < eight_bitBinary; i++) { 411 412 stringBinary = "0" + stringBinary; 413 414 415 } 416 417 } 418 419 for (int i = 0; i <= 8; i++) { 420 421 int ledState 422 = stringBinary.substring(i, i + 1).toInt(); 423 digitalWrite(led, ledState); 424 425 led = led + 1; 426 427 } 428 429}
Downloadable files
Schematic
Schematic

Comments
Only logged in users can leave comments