Need help using the Map function

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
unawoo
 
Posts: 114
Joined: Thu Apr 14, 2016 9:39 pm

Need help using the Map function

Post by unawoo »

I want to make a stroboscope using a high power led on a CPX Crickit using one of it's Drive pin.
This is how far i got in my code:

import time
from adafruit_crickit import crickit

# Strobe controled by a potentiometer

ss = crickit.seesaw
pot = crickit.SIGNAL8
# potentiometer connected to signal pin #8
# reads 5 to 1023)
crickit.drive_1.frequency = 1000

while True:
hz = ((ss.analog_read(pot),))
print(hz)
hz = map(hz, 5, 1023, 0.005, 0.1)
crickit.drive_1.fraction = 1.0 # all the way on
time.sleep(0.02)
crickit.drive_1.fraction = 0.0 # all the way off
time.sleep(hz)

And this is the error report:

raceback (most recent call last):
File "main.py", line 15, in <module>
TypeError: 'int' object is not iterable

If i comment out the map line i get this error:

Traceback (most recent call last):
File "main.py", line 19, in <module>
TypeError: can't convert tuple to float

I know the Arduino IDE well but i'm just learning circuit python.

User avatar
tannewt
 
Posts: 3314
Joined: Thu Oct 06, 2016 8:48 pm

Re: Need help using the Map function

Post by tannewt »

map is a Python builtin that means something different from arduino's map. You can use map_range from simpleio (in the bundle) instead. Hope that helps!

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”