Python Forum
Weird behavior with Led Driving code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Weird behavior with Led Driving code
#1
Hi yall, I've run into a weird issue with my project that I'm stuck on. Firstly, the git repo with all the code is here:
github.com/RGKaizen/rainbow-cloud

A little bit about the project, I have a FadeCandy connected via usb to a raspberry pi running Rasbian. fcserver runs on the Pi to talk to some LEDs (NeoPixel strips). webserver.py in my repo creates a HTTP wrapper around fcserver so I can post json to the raspberry pi to turn on LEDs.

Now in webserver.py I have 4 functions:

@_App.route('/Rainbow', methods=['POST'])
def handle_rainbow():
   try:
       data = request.get_json(force=True)
       pixels = data["pixels"]
       for p in pixels:
           _PixelState[p["channel"]][p["pos"]] = (p["red"], p["green"], p["blue"])

       for c in range(_ChannelCount):            
           if(_Client.put_pixels(_PixelState[c], channel=c)):
               print('\tsuccess {}\n').format(c)
       return '\tfail\n'
   except Exception:
       return '\tInvalidInput\n'

@_App.route('/OnBoth', methods=['GET'])
def onBoth():
   pixels_out = []
   for ii in range(_LedCount):
       red = 256
       green = 0
       blue = 0
       pixels_out.append((red, green, blue))
   _Client.put_pixels(pixels_out, channel=0)
   for ii in range(_LedCount):
       red = 0
       green = 256
       blue = 0
       pixels_out.append((red, green, blue))
   _Client.put_pixels(pixels_out, channel=1)
   return 'okay'

@_App.route('/OnA', methods=['GET'])
def onA():
   pixels_out = []
   for ii in range(_LedCount):
       red = 256
       green = 0
       blue = 0
       pixels_out.append((red, green, blue))
   _Client.put_pixels(pixels_out, channel=0)
   return 'okay'

@_App.route('/OnB', methods=['GET'])
def onB():
   pixels_out = []
   for ii in range(_LedCount):
       red = 0
       green = 256
       blue = 0
       pixels_out.append((red, green, blue))
   _Client.put_pixels(pixels_out, channel=1)
   return 'okay'

@_App.route('/Off', methods=['GET'])
def off():
   pixels_out = []
   for c in range(_ChannelCount):
       for ii in range(_LedCount):
           red = 0
           green = 0
           blue = 0
           pixels_out.append((red, green, blue))
       _Client.put_pixels(pixels_out, channel=c)
   return 'okay'
Here's where it gets interesting. OnA turns the first strip to red correctly, Off turns them both off correctly. OnBoth turns 1 red and 1 green correctly. However OnB does nothing (but returns okay meaning no apparent issue was found), and the main function handle_rainbow correctly renders effects on channel 0 (the first strip), but not on the second strip.

Given these functions and their behavior, I'm fairly confident that the _Client.put_pixels() function does behavior correctly, but it doesn't seem to do so consistently.

Is the problem some weird bug in that function nonetheless? Is there something python related that I'm just not seeing here.
I'd appreciate any advice you can offer and I'm happy to answer any questions.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Issue with uninstalling Python that is driving me crazy traxus 0 230 Mar-30-2024, 04:37 PM
Last Post: traxus
  Weird ProcessPoolExecutor initializer behavior davetapley 2 1,676 Mar-13-2023, 06:49 PM
Last Post: davetapley
  For Loops Driving Me Insane Guybrush3pwood 9 2,252 May-01-2022, 11:01 AM
Last Post: snippsat
  how to find difference between fake driving license or real using python? pjaymn 2 2,575 Dec-20-2020, 08:41 PM
Last Post: jefsummers
  python nested list assignment weird behavior eyalk1 2 4,459 Jan-16-2018, 07:32 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020