I’m using ARDUINO DUE
I tried to change the instance of the IDE that turns on and off the LED0 shaping the LED as a class and then creating and launching an LED object, the code compiles correctly, the problem is that at run once you get to the creation Item everything hangs. Could you help me fix it?
All implemented without using the class is working correctly.
please past your code
These are the sources
Sorry this is the correct main with comments in English, I have uploaded the wrong file
let’s go step by step.
1)if you define a class inside a module for the definition of the object you need to do obj=module_name.class_name()
in your case l=Led.Led()
2) in Viper pins are named as D0, D1, D2 etc as described here: http://doc.viperize.it/core.viper.stdlib/r0.3.3/pin_mapping.html
So, you can’t pass a number through a serial port to be used as it is for indicating the pin number to be used for the led.
here my suggestion (I don’t have any board with me right now so please try it and let me know)
self.pins=[D0,D1,D2,D3,D4,D5,D6] #define an array of pin names to be indexed through a number passed by the serial.read()
def setPin(self, pin):
main.py<br><pre class=" CodeBlock">import Led<br>import streams<br>s=streams.serial() #serial port<br>print("Insert the LED")<br><br>try:<br> pin=s.readline() #read and return the value letter<br> l=Led.Led() #object of Led class<br> print("create")<br> l.setPin(int(pin))<br>except Exception as e:<br> print(e) #use exception for tracking errorse in your code, you can read it directly in the serial monitor.
now it works all, thanks