ayanfeoluwaadekanye1
Published © GPL3+

LED Decimal to Binary Converter

Use the shift register and serial monitor to convert from decimal to binary and also control brightness of led

IntermediateFull instructions provided17
LED Decimal to Binary Converter

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
LED (generic)
LED (generic)
Any color is fine as long as they're all the same
×8
Jumper wires (generic)
Jumper wires (generic)
×20
Shift Register- Serial to Parallel
Texas Instruments Shift Register- Serial to Parallel
×1
Resistor 221 ohm
Resistor 221 ohm
×8
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

The Circuit

The Circuit

Code

The Code

C/C++
//Personal project
//Controlling LED with serial and shift register

//Setting up shift register Pins
int latch=10;
int clockPin=11;
int dataPin=12;
int OE=9;

//Creating a buffer to hold values
char buffer[11];

void setup() {
  // put your setup code here, to run once:

 //Setting up shift register Pins
  pinMode(latch,OUTPUT);
  pinMode(clockPin,OUTPUT);
  pinMode(dataPin,OUTPUT);
  pinMode(OE,OUTPUT);
  
  //starting Serial monitor
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
 //check if user typed something
  if (Serial.available() > 0) {    
    int index=0;   
    delay(100); // let the buffer fill up   
    int numChar = Serial.available();   
  if (numChar>11) {      
    numChar=11;   
  }    
  while (numChar--) {     
    buffer[index++] = Serial.read();    
   }    
   splitString(buffer);  
 } 
}

void splitString(char* data){
  Serial.print("Data entered: "); 
  Serial.println(data);  
  char* parameter;  
  parameter = strtok (data, " ,"); 
  while (parameter != NULL) {    
    setLED(parameter);   
    parameter = strtok (NULL, " ,"); 
    } 
    
    // Clear the text and serial buffers  
  for (int x=0; x<11; x++) {   
     buffer[x]='\0'; 
   }  
  }
 void setLED(char* data) {  
  Serial.println(data);
  if ((data[0] == 'b') || (data[0] == 'B')) {  
    int Ans = strtol(data+1, NULL, 10);  
    Ans = constrain(Ans,0,255);    
    analogWrite(OE, 255-Ans);   
    Serial.print("Brightness is set to: ");  
    Serial.println(Ans);  
    }  
   else{
     int num = strtol(data, NULL, 10);  
     num = constrain(Ans,0,255);
     digitalWrite(latch, LOW);
     shiftOut(dataPin, clockPin, LSBFIRST, num);
     digitalWrite(latch, HIGH);
     Serial.print("number is set to: ");  
     Serial.println(num); 
    }
   }

Credits

ayanfeoluwaadekanye1

ayanfeoluwaadekanye1

0 projects • 0 followers

Comments

Add projectSign up / Login