Pages: [1]   Go Down
Author Topic: Help with coding LEDs with Shift Register  (Read 166 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 1
Posts: 209
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

I have a question about shift registers.

I have watched a few tutorials on them and how they work and I have a good understanding of the mechanics. But in all of the examples of the code I have found is just shows the LEDs going on and off one after another.

I am trying to find a tutorial that goes a bit more in to detail on the coding.  One that talks about how to turn on or off a specific LED.

Thanks
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49033
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
One that talks about how to turn on or off a specific LED.
The code that turns them on one after another is doing so by turning on specific LEDs. Show some of that code, and we'll help you figure out exactly how it is working.
Logged

Lake District, UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 71
Electronics needs smoke to work, if it escapes its broken
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you may be asking about somthing i worked on recently
i wanted to get bit weighting so i could write a byte to the arduino and use it to switch individual outputs :-
(was based on an arduino  Mega)

initiate the the required pins
Code:
int ledPin = 52;
int ledPin1 = 50;
int ledPin2 = 48;
int ledPin3 = 46;
int ledPin4 = 44;
int ledPin5 = 42;
int ledPin6 = 40;
int ledPin7 = 38;

in  setup
set pins as outputs
Code:
pinMode(ledPin, OUTPUT);  // initialize the LED pin as an output:
  pinMode(ledPin1, OUTPUT); // initialize the LED pin as an output:
  pinMode(ledPin2, OUTPUT); // initialize the LED pin as an output:
  pinMode(ledPin3, OUTPUT); // initialize the LED pin as an output:
  pinMode(ledPin4, OUTPUT); // initialize the LED pin as an output:
  pinMode(ledPin5, OUTPUT); // initialize the LED pin as an output:
  pinMode(ledPin6, OUTPUT); // initialize the LED pin as an output:
  pinMode(ledPin7, OUTPUT); // initialize the LED pin as an output:
and this was in the loop
Code:
// only if there are bytes in the serial buffer execute the following code
  if(Serial.available()) {
  
     //keep reading and printing from serial untill there are bytes in the serial buffer
     //while (Serial.available()>0){
       if (Serial.available()>2){ // got 3 characters
        
// assume comes in as hundreds, tens, ones
hundreds = Serial.read() - 0x30;  // read the byte & convert from ASCII to a number
tens = Serial.read() - 0x30;
ones = Serial.read() - 0x30;

// now make into a digit
incomingByte =  hundreds*100 + tens*10 + ones;
    
 }
 Serial.print(incomingByte);
    }
 
int value = (incomingByte);
 
   digitalWrite(ledPin, (value >> 0 )% 2);// LSB
   digitalWrite(ledPin1, (value >> 1)% 2);
   digitalWrite(ledPin2, (value >> 2)% 2);
   digitalWrite(ledPin3, (value >> 3)% 2);
   digitalWrite(ledPin4, (value >> 4) % 2);
   digitalWrite(ledPin5, (value >> 5) % 2);
   digitalWrite(ledPin6, (value >> 6) % 2);
   digitalWrite(ledPin7, (value >> 7) % 2); // MSB

I sent a value from 0-255 via the serial port which switched individual pin outputs.
the value was sent in the format 000 ~255 (alway 3 characters)

Hope this was helpful
Logged

Pages: [1]   Go Up
Jump to: