Arrays in MicroPython

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
pandi999
Posts: 2
Joined: Tue Jan 28, 2020 12:11 pm

Arrays in MicroPython

Post by pandi999 » Tue Jan 28, 2020 12:13 pm

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.

User avatar
jimmo
Posts: 1139
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: Arrays in MicroPython

Post by jimmo » Tue Jan 28, 2020 12:45 pm

Hi,

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

pandi999
Posts: 2
Joined: Tue Jan 28, 2020 12:11 pm

Re: Arrays in MicroPython

Post by pandi999 » 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.

User avatar
jimmo
Posts: 1139
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: Arrays in MicroPython

Post by jimmo » Mon Feb 03, 2020 2:27 am

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).

Post Reply