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
Hats Off Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Hats Off Design Challenge
  • More
  • Cancel
Hats Off Design Challenge
Blog Easter Bonnet #3 - Flashing Light Sequence
  • Blog
  • Forum
  • Documents
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: sbi3clp
  • Date Created: 30 Aug 2014 1:44 PM Date Created
  • Views 760 views
  • Likes 1 like
  • Comments 2 comments
  • hats_off
  • easter_bonnet
Related
Recommended

Easter Bonnet #3 - Flashing Light Sequence

sbi3clp
sbi3clp
30 Aug 2014

As I said in my last post, the first thing I wanted to do with the Gemma and NeoPixels was to get the NeoPixels to blink different colours in sequence and to use the switch to start the sequence and stop it (after the lights had completed their sequence).  To try and accomplish this the circuit was set up as follows:

 

image

 

image

 

To help me with the code I went to the Learn section of the Adafruit website (https://learn.adafruit.com) and looked at other projects that had been done with the Gemma and Flora. I found the Gemma introduction (https://learn.adafruit.com/introducing-gemma) and the close encounters hat (https://learn.adafruit.com/close-encounters-hat) guides very useful for this project.

 

// Easter bonnet - Hats off challenge 2014
// Light sequence plus switch
// The following were used as guides for the code:
// Close Encouters Hat - Adafruit
// Introdution to Gemma - Adafruit

#include <Adafruit_NeoPixel.h>

int SWITCH = 0;

#define LED 1 //led attached to pin 1

//Parameter 1 = number of pixels in strip
//Parameter 2 = pin number (most are valid)
//Parameter 3 = pixel type flags, add together as needed:
//NEO_RGB Pixels are wired for RGB bitstream
//NEO_GRB Pixels are wired for GRB bitstream
//NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
//NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip)

Adafruit_NeoPixel strip = Adafruit_NeoPixel(4, LED, NEO_GRB + NEO_KHZ800);
//i.e.(4 NeoPixels, Pin 1, NEO_GRB + NEO_800KHz)

void setup() {
  strip.begin();
  strip.show();
  pinMode(SWITCH, INPUT);
  digitalWrite(SWITCH, HIGH);
}

void loop() {
  if(! digitalRead(SWITCH)){ //if the switch is pressed
    strip.setBrightness(85);
    strip.setPixelColor(0, 255,255,255); //white
    strip.setPixelColor(1, 255,255,0); //yellow
    strip.setPixelColor(2, 255,128,0); //orange
    strip.setPixelColor(3, 255,0,0); //red
    strip.show();
    delay(1000);
    strip.setPixelColor(0, 255,255,0); //yellow
    strip.setPixelColor(1, 255,128,0); //orange
    strip.setPixelColor(2, 255,0,0); //red
    strip.setPixelColor(3, 255,0,255); //pink
    strip.show();
    delay(1000);
    strip.setPixelColor(0, 255,128,0); //orange
    strip.setPixelColor(1, 255,0,0); //red
    strip.setPixelColor(2, 255,0,255); //pink
    strip.setPixelColor(3, 0,0,255); //blue
    strip.show();
    delay(1000);
    strip.setPixelColor(0, 255,0,0); //red
    strip.setPixelColor(1, 255,0,255); //pink
    strip.setPixelColor(2, 0,0,255); //blue
    strip.setPixelColor(3, 128,255,0); //green
    strip.show();
    delay(1000);
    strip.setPixelColor(0, 255,0,255); //pink
    strip.setPixelColor(1, 0,0,255); //blue
    strip.setPixelColor(2, 128,255,0); //green
    strip.setPixelColor(3, 255,255,255); //white
    strip.show();
    delay(1000);
    strip.setPixelColor(0, 0,0,255); //blue
    strip.setPixelColor(1, 128,255,0); //green
    strip.setPixelColor(2, 255,255,255); //white
    strip.setPixelColor(3, 255,255,0); //yellow
    strip.show();
    delay(1000);
    strip.setPixelColor(0, 128,255,0); //green
    strip.setPixelColor(1, 255,255,255); //white
    strip.setPixelColor(2, 255,255,0); //yellow
    strip.setPixelColor(3, 255,128,0); //orange
    strip.show();
    delay(1000);
    strip.setPixelColor(0, 0,0,0); //clear
    strip.setPixelColor(1, 0,0,0);
    strip.setPixelColor(2, 0,0,0);
    strip.setPixelColor(3, 0,0,0);
    strip.show();
    delay(1);
   // when stop pressed, the sequence continues to the end and finishes on the final colour.
   // To turn it "off" clear added to the list so it stops on this.
   // The short delay hides the clear stage from the loop
  } else {
    digitalWrite(SWITCH,HIGH);
  }
}

 

The idea is that each NeoPixel will run through a sequence of colours, including white, yellow, orange, red, pink, blue and green when the button/switch is pressed. The first NeoPixel (0) would run the sequence in this order. The second (1) would start from yellow and carry on in the same sequence ending on white. The third (2) would start from orange and so on. Each colour is lit for approximately 1 second before changing to the next colour. The sequence then runs in a loop until the switch is pushed again. Although at this point, the sequence doesn’t stop dead, but carries on until the last colour in the sequence is lit and then goes off. In the code, you will notice that I also put a clear section in. This was added because when stopping the sequence the NeoPixel would remain lit the last colour. By putting the delay to 1 (a thousandth of the other colours) the clear is unnoticeable in the sequence.

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

So that is the light sequence I would like to use in my hat. It will probably change as the hat evolves. Currently I’m waiting for the bonnet/hat (due to arrive the middle of September), which will act as the base of my design. Hopefully, when this arrives I can make more (and better) judgement calls on the final aesthetics of my Easter bonnet.

  • Sign in to reply
  • sbi3clp
    sbi3clp over 11 years ago in reply to DAB

    Thanks image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 11 years ago

    Good post.

     

    Not bad for your first programming challenge.

     

    Now on to the fun.

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
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