element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Change multiple values in a boolean array?
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 4 replies
  • Subscribers 393 subscribers
  • Views 792 views
  • Users 0 members are here
Related

Change multiple values in a boolean array?

l1t7l3ph0o7
l1t7l3ph0o7 over 10 years ago

I can't seem to figure this one out,

the scenario is, I have two shift registers connected to my arduino and 16 leds connected to them.

I have a boolean array of 16, then I wrote a function that writes the array to the shift registers. Thats what the writereg(); is

 

I can do neat things like:

for (int i = 1; i<16; i++){

registers[i] = high

}

writereg();

and one led will light up one after the other

 

But is there a way to light up specific multiple leds without a for loop in a single line of code?

The only thing I can think to do is:

registers[1] = HIGH;

registers[4] = HIGH;

registers[10] = HIGH;

registers[16] = HIGH;

writereg();

it would be neat if I could do something like this:

registers[1,4,10,16] = HIGH;

writereg();

anyone know, just curious if there is a less caveman approach to what I'm doing

  • Sign in to reply
  • Cancel

Top Replies

  • Robert Peter Oakes
    Robert Peter Oakes over 10 years ago +1
    The answer to your question is quite simple Direct port manipulation The ATMEGA328 has 3 sets of ports, A, B and C, not all pins of each port are available but it is basically laid out like this B (digital…
Parents
  • bobcroft
    0 bobcroft over 10 years ago

    Jory,

              Peter gave you some good information on binary bit manipulating.  However I think what you want to do is to set certain bits of the 16 shift register bits to on with the other bits off.

    If you use the Arduino SHIFTOUT function with something like the code below,

     

    // Send the value as a binary sequence to the 595's

        shiftOut(dataPin, clockPin, MSBFIRST, ByteHigh);

        shiftOut(dataPin, clockPin, MSBFIRST, ByteLow);

     

    Prior to sending the data you should be able to set the high and low bytes to the value you want.  You can 'mask' the high or low bytes to set the specific outputs to a Binary 1.  In this way you can set multiple outputs of the shift registers with very little code.

     

    Please note that I have not tried this myself.

     

    Hope that helps

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • bobcroft
    0 bobcroft over 10 years ago

    Jory,

              Peter gave you some good information on binary bit manipulating.  However I think what you want to do is to set certain bits of the 16 shift register bits to on with the other bits off.

    If you use the Arduino SHIFTOUT function with something like the code below,

     

    // Send the value as a binary sequence to the 595's

        shiftOut(dataPin, clockPin, MSBFIRST, ByteHigh);

        shiftOut(dataPin, clockPin, MSBFIRST, ByteLow);

     

    Prior to sending the data you should be able to set the high and low bytes to the value you want.  You can 'mask' the high or low bytes to set the specific outputs to a Binary 1.  In this way you can set multiple outputs of the shift registers with very little code.

     

    Please note that I have not tried this myself.

     

    Hope that helps

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube