Python Forum
Adding Cosinus as utime.sleep variable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding Cosinus as utime.sleep variable
#1
Okay, so I´m having trouble using the Cosinus as variable for ms. I want Cosinus(x) to reach it´s limit at led 11, then go back down again, so I get a lighting effect like the K.I.T.T from Knight Rider, but i really can`t get it to run. Any suggestions to make my code better in general are also welcome, I´m a bloody beginner.

import display
import leds
import utime
import color
import display
import math
red=color.Color(255,0, 0)
green=color.Color(0, 255, 0)
toright=True
a=0
b=0
x=math.cos()
while True:
    leds.set(a, red)
    leds.set(b, green)
    utime.sleep_ms(x+100)
    leds.clear()

    if toright==True:
        a=a+1
        b=a-1
    else:
        a=a-1
        b=a+1
    if a==10:
        toright=False
    if a==0:
        toright=True
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Use subprocess.Popen and time.sleep chucky831 2 1,890 Aug-11-2022, 07:53 PM
Last Post: carecavoador
  Adding variable to Python code - media sentiment analysis Marietje 3 2,510 May-25-2021, 05:15 PM
Last Post: jefsummers
  Can you end the Time.sleep function boier96 9 9,219 Jan-16-2021, 10:09 PM
Last Post: Serafim
  time.sleep mtnwinds 4 2,792 May-21-2020, 10:12 AM
Last Post: Larz60+
  time.sleep works erratically, a bug in Python? stipcevic 2 3,817 Jan-21-2020, 09:38 PM
Last Post: Marbelous
  Adding markers to Folium map only adding last element. tantony 0 2,094 Oct-16-2019, 03:28 PM
Last Post: tantony
  How to achieve close to 1ms time.sleep kwekey 1 14,793 Mar-25-2019, 02:52 AM
Last Post: Larz60+
  If error sleep and then try again from there CaptainCsaba 2 2,643 Mar-01-2019, 06:28 AM
Last Post: CaptainCsaba
  time.sleep(...) problem DPaul 3 2,740 Jan-28-2019, 11:40 AM
Last Post: Larz60+
  Alternative for time.sleep()? Atkion 1 7,442 Jan-15-2018, 10:25 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

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