Also new to BP...

Hi,

I checked out the other post but I’m in a bit of a different boat so I’m not sure if all the stuff from that thread is applicable. I’m trying to work on an interactive LED strip application, where users can enter certain parameters and expect a specific animation to occur. I’m working with the LPD8806 on an RPi 3, and I have Bibliopixel 3 installed. For now I expect to enter parameters in through the command line, but eventually I want to have an iOS/Android app where those parameters can be entered, controlling the RPi and therefore LED strip remotely via Bluetooth. So I have two questions, I guess: 1) can what I want to do be accomplished using BiblioPixel? 2) Can I use the Animations and JSON object approach or is this a situation where directly coding in Python is beneficial (mostly worried about interactive-ness of program and eventual Bluetooth incorporation)? I feel lost starting on either approach, so starter code or advice is much appreciated.

Thank you for being so invested in my project!

On Arduino I had several of these features running, but I just wanted to get a prototype fully integrated before I built it up. It’s good to hear that I can use JSON for all this, and after reading up on it it makes more sense, but I’m still not sure about what it looks like with BP. What text files am I writing, and what commands am I running on the command line to get an animation to run? Your advice on structuring this project sound reasonable, but I’m still struggling to translate this into action on my part.

Looking forward to your response, when you get the time.

···

On Aug 14, 2017 3:50 PM, “Tom Swirly” tom@swirly.com wrote:

Sorry for the delay!

Two things happened - it turns out that I had put a bug into 3.2 and I had to fix it; and this answer got out of control. :smiley:


I’m going to start with some ideas on how to set up the project in general, and then move towards how to accomplish this with BiblioPixel.

First, let’s look at the problem in detail to make a full model of the whole swimmer’s world! Designing for the full model isn’t much more work, because you don’t have to fill in the programming details until the end, if ever - but it clarifies your mind. :slight_smile:

1. Full feature list.

So let’s imagine a fully-fledged, amazing swimmer’s guide! Don’t worry, we won’t do this all at once, but it’s good to really get an idea of the possibilities.

What features or settings would you potentially want that aren’t mentioned above?

  1. length of the guide (lighted part) in pixels.
  1. color or intensities for those guide pixels.
  1. Separately, color or intensity changes of the guide pixels along the length of the path (you might want the color to get brighter as they get to the end).
  1. markers: regular markers of a different color every e.g. 5 meters.
  1. an offset:

You want the light to be exactly in front of the swimmer. Based on the swimmer’s height, the style of swimming and how they enter the pool as a result, the swimmer will start the race at slightly different points in the pool in different races. You want to be able to tweak that.

  1. Support for laps and turnovers.

You need to account for the fact that the swimmer has to slow down to turn over - the speed cannot be uniform.

  1. Relay races.
  1. Non-constant swim speeds.

Your model, as it is now, is trying to get the swimmer to go at a constant speed. But this might not be the best strategy to win.

  1. “interactive driving” from the coach.

It should be possible for the coach to dynamically accelerate or decelerate the guide during the swim, because the swimmer is falling behind or to goad the swimmer to greater speed.

  1. intervals/“rest periods” between laps and groups of laps.

I think we’ll stop here, because I don’t want to completely overwhelm you!

The idea is not to expect to implement these features overnight, perhaps ever, but at least to have an idea that these features are possible, and to consider them in the back of your head.

2. Simplify your life by representing the problem in data.

This is a great trick that works on many programming problems!

Usually you have some set of controls or configurations or a command line or something like that which controls what your program actually does. In this case, there are two possibilities - a command line, and a bluetooth app - and of course if the program became popular you’d want more choices yet.

So you can make your life much easier by adding an extra step.

Instead of reading the configuration and doing the work in one step, instead create a piece of dumb data in the first step, and then in a separate second step, use that dumb data to do the work.

This is an example of “loose coupling”. The big advantage is that you can test all the parts much more easily, and when you need to write a new front end, or a new back end, you can do it without breaking all the other parts.

It’s also really good because when you specify the dumb data, you’re forced to specify the details of how to represent the problem.

Today, the simplest way to represent dumb data is JSON - because every browser and every programming language understands it, and because it’s really minimal.

So I suggest you start by creating JSON structures that represent the setups or configurations for your problem.

I see at least three different structures:

  1. The specific set with fields like set_type and distance. This will change often. Example:

{

"set_type": "regular",
"distance": 100,
"interval": 90,
"pace": 70

}

  1. The installation which has information specific to the hardware installation in the pool. This will only change when you make a new installation, which will be rare. Example:

{

"pixel_count": 256,
"marker_spacing": 1

}

  1. The skin which describes what the animation actually looks like. You probably will experiment a lot with skins, and then settle on a few that you like. Example:

{

"length": 8,
"color": "red",
"markers": 1,
"offset": 2

}

  1. The command which starts, stops and pauses the animation. Example:

{

"command": "start"

}

Notice that you’re going to actually have to specify units for all these values - and make sure everyone agrees about them! In the above, distance, interval and marker_spacing are in yards, pace is in seconds.

So your command line, or your saved data, or your Bluetooth application, are all going to create one or more of these JSON objects - and then pass them to a single central program that will actually run the animation.

But :slight_smile: I am out of time for tonight. Write back and I’ll finish this tomorrow!

On Sun, Aug 13, 2017 at 2:27 PM, Tom Swirly tom@swirly.com wrote:

[Re-adding BiblioPixel Users - with Charles’ permission!)


/t

https://tom.ritchford.com

https://tom.swirly.com

On Fri, Aug 11, 2017 at 9:05 PM, Charles Van Eijk cvaneijk@g.hmc.edu wrote:

Thank you for that! I’m impressed by your response time.

Okay, I’m going to lay out my objective to give you some more background, and that’ll hopefully give a sense of the big picture.

My goal here is to develop a product that will be used by swimmers to guide their pace via a pulse of light travelling along the strip while they’re swimming. Ever seen the world record line they display on TV during Olympic/World Championship swimming? I kind of want it to be like that. The LED strip will be located on the pool floor and run the length of a lane, with an RPi attached (out of the water). Ultimately, the program is to be used by coaches on deck via their phones. Coaches will be asked a series of questions about the set they are about to dish out, and then the animation will run when they tell it to start. This probably sounds a bit abstract at this point, so I’ll give you an example.

Note: The end goal will be for this interaction to occur on a phone, but for now I imagine it will happen on the command line.

Regular or Irregular Set?

Regular

You have chosen regular. How many times is the distance repeated?

10

What is the distance (yards)?

100

What is the interval (seconds)?

90

Pace (seconds)?

70

Alrighty, the set is 10 100s on the 1:30 with 1:10 goal pace. Hit enter to start.

What is the next set?

And so on

This means a pulse of light will traverse the lane 4 times (100 yards/25 yard lane), and arrive back where it started after 1 minute and 10 seconds. 20 seconds later (1 minute and 30 seconds after original start time), it will repeat the process. This whole process will happen 9 more times, for a total of 10. If you’re a swimmer in that lane, that means you will try keep pace with the pulse over the course of 100 yards. You get 20 seconds rest, and then you do that 9 more times. I’m working off the assumption that you don’t know anything about swimming, forgive me if I’m wrong. I hope this has been informative instead of confusing.

I already successfully programmed this to run on Arduino, but I was having trouble integrating it with Bluetooth, so I switched to RPi. I could attach the Pool Pacer LED Animation program I had for Arduino if you wanted to take a look. Hopefully this gives you a sense of what I’m trying to accomplish. If you have any more questions let me know. Otherwise, advice on how to get started on this is much appreciated.

I’m going to send this - and then respond to it “fairly shortly”. :slight_smile:


/t

https://tom.ritchford.com

https://tom.swirly.com