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 Hats Off Fascinator 10: Goldfish Writes Code
  • Blog
  • Forum
  • Documents
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: brenyc13
  • Date Created: 20 Sep 2014 10:36 AM Date Created
  • Views 487 views
  • Likes 0 likes
  • Comments 1 comment
  • jaunty_fascinator
  • hats_off
  • adafruit
Related
Recommended

Hats Off Fascinator 10: Goldfish Writes Code

brenyc13
brenyc13
20 Sep 2014

A post in which I explain that my short term memory resembles that of a goldfish.


image

Apologies for the skimpy post this week. It takes me 100 times longer than a normal human to program something because I keep forgetting how code works. Slow pace = small result.


Programming Schmogramming

So I’ve been trying to write the part of the code that takes the accelerometer data and uses it as an input to change the color and intensity of the NeoPixels. I’ve managed to turn this into a fun marriage-straining exercise in which I just try out whatever I think will work and then ask my spouse for the correct way of doing it. I think he’s getting frustrated with me. He said that it’s like I’m trying to write a novel without being able to read a sentence. This is probably true. But, as I told him, sometimes it’s more motivating to shoot for the complex and crazy, even when it’s utterly unrealistic.


An Approach

I like to think on paper so I wrote out a little blurb on how I want the accelerometer to interact with the NeoPixels: There are two aspects of the NeoPixels that will change: color and intensity. So the program needs “boxes” for those two things and then it needs to always push these values out to the LEDs. The information from the accelerometer changes whatever is in the boxes for color and intensity. The intensity starts at 0 and the color starts at whatever value is furthest from red (I think purple on the hue scale). Then, when there is an accelerometer event powerful enough to trigger it, the intensity increases by 10 and the color increases by 10 (these values will all get finessed). Then there needs to be some kind of time-based fade-out. If another event occurs before the end of the fade-out then the color/intensity increase will be added to its current state is.


I’m not sure if that will really make sense to anyone else but it’s what I’ve been working with in my fun trial-and-error way. Rather than use the serial debugging, I ended up just hooking up a NeoPixel and trying things out as I go.


Piddling Progress

As of right now, I’ve gotten the light to increase intensity by 10 anytime there’s movement above a certain threshold (aka when the vector length of the combined x,y,z values is more than 4000). The concept that keeps tripping me up is that a variable’s name isn’t the thing itself but rather a container called the thing. So when I make something called “current_brightness” I can just keep putting different values inside of it (current_brightness = current_brightness + 10 = MIND BLOWN). I have to continually remind myself that this is not a symbol language; it’s more like labeling a bunch of drawers and boxes. But I’m basically like that guy from Memento with anterograde amnesia, thereby working at a snail’s pace and torturing my spouse in a fun new way as he attempts to help me without helping too much.


As riveting as you must find this, I’m really hoping to step it up this weekend. For reading this far, I reward you with a picture of a pretty yellow fascinator that I spotted yesterday:


image

  • Sign in to reply
  • DAB
    DAB over 10 years ago

    Hi Barb,

     

    I know what you mean.  Right now between medication and allergies my brain is working on two of its eight cylinders.

    One thing to remember about accelerator chips is that they respond to rate of change, not position.

    You can derive location and position from accelerator data, but it is a nasty math transformation.

    You can probably get the effect you want, but you will need to choreograph your head movements to get it to work.

     

    I do like the yellow lace.  You can do a lot of interesting things playing with different color combinations.

     

    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