Page 1 of 1

Arrays in MicroPython

Posted: Tue Jan 28, 2020 12:13 pm
by pandi999
Store the value of switch presses and their delay intervals in a variable and try blinking the onboard red LED after 10 second delay according to the switch presses.

Re: Arrays in MicroPython

Posted: Tue Jan 28, 2020 12:45 pm
by jimmo
Hi,

Are you looking for a way to do what you describe? Any additional context would be helpful :)

Re: Arrays in MicroPython

Posted: Wed Jan 29, 2020 6:42 am
by pandi999
I need to record the value of USR switch of Py board in an array which will run for 10 Seconds and after that read the array which contains the values of USR switch . According to the elements that are stored in array my LED needs to get lighted up.

Re: Arrays in MicroPython

Posted: Mon Feb 03, 2020 2:27 am
by jimmo
pandi999 wrote:
Wed Jan 29, 2020 6:42 am
I need to record the value of USR switch of Py board in an array which will run for 10 Seconds and after that read the array which contains the values of USR switch . According to the elements that are stored in array my LED needs to get lighted up.
One important thing is how quickly you want to sample the switch (i.e. how many times per second do you update the array). This will affect how accurately you can measure the timing.

But something like (untested):

Code: Select all

import pyb, time

def measure():
  samples = []
  sw = pyb.Switch()
  for i in range(100):
    samples.append(sw.value())
    time.sleep_ms(100)
  return samples
  
print(measure())
[code]

That will give you a list of 100 True/False values (10 per second).