The Raspberry Pi Thread [5]


  1. Posts : 15,037
    Windows 10 IoT
    Thread Starter
       #331

    This waht I had and was tested working fine.
    Code:
    def ledtemp():
        if sensor.get_sensor_data(): 
           t = sensor.data.temperature 
           t = round(t)
        if t > 28:                                         # Realy Hot 
            set_multiple_pixels(range(0,27), 255, 0, 0)    # Red
            set_multiple_pixels(range(27,28), 255,140, 0)  # Orange
            M = (t - 56) * (-1)
            # R R R R R R R R R R R R R R R R R R R R R R R R R R R O
        elif t > 0 and t <= 28:                            # Main
            set_multiple_pixels(range(0,3), 255, 140, 0)   # Orange
            set_multiple_pixels(range(3,16), 0, 255, 0)    # Green
            set_multiple_pixels(range(16,28), 255, 255, 0) # Yellow
            M = (28 - t)
            # O O O G G G G G G G G G G G G G Y Y Y Y Y Y Y Y Y Y Y Y
        elif t <= 0 and t >= -27:                          # Cold 
            ledshim.set_all(0, 0, 255)                     # Blue
            M = (t * (-1))
            # B B B B B B B B B B B B B B B B B B B B B B B B B B B B
        elif t < -27:                                      # Really cold
            set_multiple_pixels(range(0,3), 255, 255, 255) # Blue
            set_multiple_pixels(range(3,28), 0, 255, 255)  # Aqua
            M = ((28 + t) * (-1))
            # B B B A A A A A A A A A A A A A A A A A A A A A A A A A
        ledshim.set_pixel(M, 0, 0, 0)
        ledshim.show()
    And this is my new untested code

    Code:
    def ledtemp():
        if sensor.get_sensor_data(): 
           t = sensor.data.temperature 
           t = round(t)
        if t > 40:                                         # Realy Hot 
            set_multiple_pixels(range(0,28), 255, 0, 0)    # Red
            M = (t - 68) * (-1)
            # R R R R R R R R R R R R R R R R R R R R R R R R R R R R
        elif t > 12 and t <= 40:                           # Main
            set_multiple_pixels(range(0,11), 255, 0, 0)    # Red
            set_multiple_pixels(range(11,16), 255, 140, 0) # Orange
            set_multiple_pixels(range(16,28), 0, 255, 0)   # Green
            M = (40 - t)
            # R R R R R R R R R R R O O O O O G G G G G G G G G G G G
        elif t <= 12 and t >= 0:                          # Cold 
            set_multiple_pixels(range(0,12), 255, 255, 0) # Yellow
            set_multiple_pixels(range(12,28), 255, 255, 255)  # Aquat
            M = (12 - t)
            # Y Y Y Y Y Y Y Y Y Y Y Y B B B B B B B B B B B B B B B B
           
        elif t < 0 and t >= -15:                          # Cold 
            set_multiple_pixels(range(0,12), 255, 255, 0) # Yellow
            set_multiple_pixels(range(12,28), 255, 255, 255)  # Aquat
            M = (t * (-1)) + 12
            # Y Y Y Y Y Y Y Y Y Y Y Y B B B B B B B B B B B B B B B B
        elif t < -15:                                      # Really cold
            set_multiple_pixels(range(0,28), 0, 255, 255)  # Aqua
            M = ((t + 16) * (-1))
            # A A A A A A A A A A A A A A A A A A A A A A A A A A A A
        ledshim.set_pixel(M, 0, 0, 0)
        ledshim.show()
    Last edited by alphanumeric; 20 Aug 2019 at 10:29.
      My Computer


  2. Posts : 5,707
    insider build 10586.3 win10 pro 64
       #332

    still all greek to me . this is old i think but some neat looking tools for kids and young adults into learning Pi Installing the .NET Core 2.x SDK on a Raspberry Pi and Blinking an LED with System.Device.Gpio - Scott Hanselman
      My Computer


  3. Posts : 15,037
    Windows 10 IoT
    Thread Starter
       #333

    Just tested my new LED Shim Temperature code. No errors, woot. This new scale should be ideal for my indoor weather clock. It goes from 13c at the bottom to 40c at the top. Unless we have a power failure in the middle of winter it should never leave that scale. Its green from 13 to 24, orange from 25 to 29, and red above 30c. I think I'm going to put this code on my portable too, just to be consistent.
    The ideal way to do this would be to have a static marker in the middle of the LED Shim that never moves. Then have a sliding scale that moves with the temperature. The colored bands would move up and down depending on the temperature. I'm thinking that would be really hard to code though. I may see if its doable at some point, not today though.
      My Computer


  4. Posts : 15,037
    Windows 10 IoT
    Thread Starter
       #334

    Started redoing my LED Shim barometric Pressure code. I switch my indoor Weather Clock to show pressure in the winter. No real advantage to showing the temperature when all the doors are closed and the furnace is on. It just sits at 22c all day lol.
    I want to have one scale that goes from very low to very high. I'm going to lose a bit of accuracy but only on the LED shim. I only have 28 LED's to work with. The normal Sense Hat display is unaffected.
    This is what I have so far, and its not tested yet. Might still be a bug or two in my code. The first column is the color I want the LED. The next column is the LED number and then the pressure it represents.
    I used 30 LED's to make the math easier, the two end ones are only imaginary. The odds of the pressure getting that high or that low are very remote.

    R - 1069
    R - 0
    R
    R
    R
    R - 4 - 1048 - Very High
    B - 5 - 1047 - High
    B
    B
    B
    B
    B - 10 - 1026 - High
    G - 11 - 1025 - Mid
    G
    G
    G
    G
    G - 16 - 1004 - Mid
    Y - 17 - 1003 - Low
    Y -
    Y -
    Y -
    Y -
    Y - 22 - 982 - Low
    R - 23 - 981 - Very Low
    R -
    R -
    R -
    R - 27 -
    R - 960

    1069 - 960 = 109

    110 / 30 = 3.66666
    M1 = P - 961 << Gives me a number between 0 and 109
    M2 = M1 / 3.666 << Gives me a number between 30 and 0
    M3 = (M2 - 30) * -1 << Swaps the order, 30 becomes 0 and 0 becomes 30 as my LED shim is upside down / reversed.


    The actual python code is as follows. I'm going to try and test it sometime today.

    def ledpress():

    if sensor.get_sensor_data():
    p = sensor.data.pressure
    p = round(p)



    set_multiple_pixels(range(0,5), 255, 0, 0) # Red - Very High
    set_multiple_pixels(range(5,11), 0, 0, 255) # Blue - High
    set_multiple_pixels(range(11,17), 0, 255, 0) # Green - Mid Range
    set_multiple_pixels(range(17,23), 255, 255, 0) # Yellow - Low
    set_multiple_pixels(range(23,28), 255, 0, 0) # Red - Verry Low







    N = ((p- 961) / 3.666)
    M = ((N -30) * (-1))


    ledshim.set_pixel(M, 0, 0, 0)
    ledshim.show()
    Last edited by alphanumeric; 22 Aug 2019 at 09:54.
      My Computer


  5. Posts : 15,037
    Windows 10 IoT
    Thread Starter
       #335

    Ended up with this, seems to work Ok.

    Code:
    def ledpress():
    
        if sensor.get_sensor_data(): 
           p = sensor.data.pressure 
           p = round(p)
    
    
        set_multiple_pixels(range(0,5), 255, 0, 0)         # Red    - Very High
        set_multiple_pixels(range(5,11), 0, 0, 255)        # Blue - High
        set_multiple_pixels(range(11,17), 0, 255, 0)       # Green  - Mid Range
        set_multiple_pixels(range(17,23), 255, 255, 0)     # Yellow   - Low
        set_multiple_pixels(range(23,28), 255, 0, 0)       # Red    - Verry Low
        
        N = ((p- 961) / 3.6) 
        N = round(N)
        M = ((N -30) * (-1))
        
        ledshim.set_pixel(M, 0, 0, 0)    
        ledshim.show()     
    EDIT: My pointer is a bit low, going to have to tweak my math a little bit I think. The actual barometer reading was just in the Mid Range. My pointer should have been on the lowest Green LED, but my pointer was in the top of the yellow bit. Having to round off my number likely has something to do with it. I think I need to divide by 3.7 or 3.8 instead of 3.6. The math actually kicked out 3.66666666...

    I'll play with it latter on today, I just put it all back together again. Maybe I'll grab my indoor one, its not in a case so plugging in cables is easy.
    Last edited by alphanumeric; 22 Aug 2019 at 10:22.
      My Computer


  6. Posts : 5,707
    insider build 10586.3 win10 pro 64
       #336

    alphanumeric said:
    Ended up with this, seems to work Ok.

    Code:
    def ledpress():
    
        if sensor.get_sensor_data(): 
           p = sensor.data.pressure 
           p = round(p)
    
    
        set_multiple_pixels(range(0,5), 255, 0, 0)         # Red    - Very High
        set_multiple_pixels(range(5,11), 0, 0, 255)        # Blue - High
        set_multiple_pixels(range(11,17), 0, 255, 0)       # Green  - Mid Range
        set_multiple_pixels(range(17,23), 255, 255, 0)     # Yellow   - Low
        set_multiple_pixels(range(23,28), 255, 0, 0)       # Red    - Verry Low
        
        N = ((p- 961) / 3.6) 
        N = round(N)
        M = ((N -30) * (-1))
        
        ledshim.set_pixel(M, 0, 0, 0)    
        ledshim.show()     
    EDIT: My pointer is a bit low, going to have to tweak my math a little bit I think. The actual barometer reading was just in the Mid Range. My pointer should have been on the lowest Green LED, but my pointer was in the top of the yellow bit. Having to round off my number likely has something to do with it. I think I need to divide by 3.7 or 3.8 instead of 3.6. The math actually kicked out 3.66666666...

    I'll play with it latter on today, I just put it all back together again. Maybe I'll grab my indoor one, its not in a case so plugging in cables is easy.
    great job ,makes me wish i could grasp coding .. seen this on pimoroni, great test of one's soldering skills Stringy – Pimoroni Store
      My Computer


  7. Posts : 15,037
    Windows 10 IoT
    Thread Starter
       #337

    I just now finished testing my revised simpler code. Working fine as near as I can tell. I like this display a lot better than my other setup. At some point I'll do a proper test by incrementing my value for pressure manually from the very low to very high. Then watch my marker slowly creep up the LED Shim. I speed up the scroll speed to make it get done quicker then slow it back down to normal speed when done. I should do it now but I juts don't feel like doing it tonight.

    Code:
    def ledpress():
        if sensor.get_sensor_data(): 
           p = sensor.data.pressure 
           p = round(p)
        set_multiple_pixels(range(0,5), 255, 0, 0)         # Red    - Very High
        set_multiple_pixels(range(5,11), 0, 0, 255)        # Blue - High
        set_multiple_pixels(range(11,17), 0, 255, 0)       # Green  - Mid Range
        set_multiple_pixels(range(17,23), 255, 255, 0)     # Yellow   - Low
        set_multiple_pixels(range(23,28), 255, 0, 0)       # Red    - Very Low
        
        N = ((p - 961) / 3.76)
        N = round(N)
        M = (29 - N) - 1
        if M < 0:
            M == 0
        elif M > 27:
            M == 27
        
        ledshim.set_pixel(M, 0, 0, 0)    
        ledshim.show()     
    
      My Computer


  8. Posts : 15,037
    Windows 10 IoT
    Thread Starter
       #338

    If I was going to get one of those I think I'd get this one, PissOff – Pimoroni Store
      My Computer


  9. Posts : 5,707
    insider build 10586.3 win10 pro 64
       #339

    ha-ha never seen that one ,I like it ,maybe i'll get both lol
    alphanumeric said:
    If I was going to get one of those I think I'd get this one, PissOff – Pimoroni Store
      My Computer


  10. Posts : 15,037
    Windows 10 IoT
    Thread Starter
       #340

    I like this one too, Touchy – Pimoroni Store

    Just be advised that your going to likely need a very fine tip soldering iron, and very steady hands, for any of those that have surface mount components in that kit. Some of those surface mount IC's have very small leads with very close spacing.

    EDIT: I take that I like this one too comment back. At first glance I though it had one of those thin speakers on the end. Its actually just a a fancy touch / scroll pad.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 20:04.
Find Us




Windows 10 Forums