Saturday, July 29, 2017

7 Segment LED and Potentiometer Control

I harvested a nice single 7-segment LED display off a control panel board of an old printer/scanner that was discarded on the sidewalk. It turns out to be this component. After looking at some Arduino 7-segment display tutorials I focused on this one and saw that I could connect the pins directly to the Arduno pinouts without needing any driver. I could also figure out the pins for each segment by trial-and-error and the datasheet showed it is common anode, so needed to connect to 5V not GND, and adjust the sample sketch in the tutorial accordingly.

I got it counting 0-9 then I added a pot for a little more fun.
Here is the sketch that allows you to turn the pot to set the digit displayed.
 int num_array[10][7] = { { 0,0,0,0,1,0,0 },  // 0  
              { 0,0,1,1,1,1,1 },  // 1  
              { 1,0,0,1,0,0,0 },  // 2  
              { 0,0,0,1,0,1,0 },  // 3  
              { 0,0,1,0,0,1,1 },  // 4  
              { 0,1,0,0,0,1,0 },  // 5  
              { 0,1,0,0,0,0,0 },  // 6  
              { 0,0,0,1,1,1,1 },  // 7  
              { 0,0,0,0,0,0,0 },  // 8  
              { 0,0,0,0,0,1,0 }};  // 9  
 #define POT A0  
 void setup()   
 {   
  // set pin modes  
  pinMode(2, OUTPUT);    
  pinMode(3, OUTPUT);  
  pinMode(4, OUTPUT);  
  pinMode(5, OUTPUT);  
  pinMode(6, OUTPUT);  
  pinMode(7, OUTPUT);  
  pinMode(8, OUTPUT);  
  Serial.begin(9600);  
 }  
 void loop()   
 {  
  int setNum = analogRead(POT);  
  setNum = map(setNum,0,1023,0,10);  
  Serial.println(setNum);  
  if(setNum<10) Num_Write(setNum);   
 }  
 // this functions writes values to the sev seg pins   
 void Num_Write(int number)   
 {  
  int pin= 2;  
  for (int j=0; j < 7; j++) {  
   digitalWrite(pin, num_array[number][j]);  
   pin++;  
  }  
 }  

Here's a video:

1 comment :

Rylee Schmidt said...

Great to see you again! I've read every word on this blog, and after initial excitement became quite sad not seeing any new posts for a while. Good luck with everything! Thank you for Your work! check it out wyze discount code