Hi Sara
I have spent some time trying to self figure out the following ( some is earlier code you helped me with). I only ask when I get really stuck and spent much time googling before I ask RNT
from machine import Pin, I2C, PWM, ADC
from time import sleep
import ssd1306
# fitted a Button used to force machine stop while in code development
# Break workround required to enable uPycraft to get a connection to
# COM Port so can modify code, not needed when final code developed
button = Pin(36, Pin.IN, Pin.PULL_UP)
#PWM frequency
frequency = 50
#Graphics ESP32 Pin assignment
i2c = I2C(-1, scl=Pin(22), sda=Pin(21))
# ESP8266 – Pin assignment
#i2c = I2C(-1, scl=Pin(5), sda=Pin(4))
oled_width = 128
oled_height = 64
display = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
#Thruster Motor assignments
motor = PWM(Pin(5), frequency)
pot = ADC(Pin(34))
pot.width(ADC.WIDTH_10BIT)
pot.atten(ADC.ATTN_11DB)
#simulated battery pot instanceiated object ( not in use at present since trying to read the existing pot first used for pwm as proof of code concept)
bat_pot = ADC(Pin(35))
bat_pot.width(ADC.WIDTH_10BIT)
bat_pot.atten(ADC.ATTN_11DB)
RNT code provided earlier
def scale_value_args(pot_val, in_min, in_max, out_min, out_max):
scale_value = (pot_val – in_min) * (out_max – out_min) / (in_max – in_min) + out_min
return scale_value
#Main body of code after defining above environment ( from earlier RNT assistance )
while True:
pot_val = pot.read()
duty_cycle = scale_value_args(pot_val, 0, 1023, (1023/20), (1023/10))
print(duty_cycle)
motor.duty(int(duty_cycle))
sleep(0.2)
#if (int(duty_cycle)) > 75:# if i comment this out works for pot and hw BUTTON reset i hooked up to force HW reset as I am describing the error to RNT
# Draw a filled rectangle display.fill_rect(x, y, w, h, c) #works ok
display.fill_rect(0, 0, 127, 67, 1)# main white box fill works ok
display.fill_rect(5, 5, 118, 54, 0)# main black box fill works ok
display.fill_rect(12, 10, 12, 44, 1)# first segment works ok
display.fill_rect(30, 10, 12, 44, 1)# second segment works ok
display.fill_rect(48, 10, 12, 44, 1)# third segment works ok
display.fill_rect(66, 10, 12, 44, 1)# fourth segment works ok
display.fill_rect(84, 10, 12, 44, 1)# fifth segment works ok
display.fill_rect(102, 10, 12, 44, 1)# sixth segment works ok
display.show() # works ok
# Force exit
if button.value()==True:# I NEED THIS IN TO ALLOW RESETTING OF BOARD TO ALLOW UPYCRAFT TO COM3 Port CONNECT OTHERWISE CANT CONNECT !!!!!!
break
I need the force exit code in above to allow UpyCraft to get a look in since the board wont allow COM3 connection when code running , if I comment it out i cant reprogram without reflashing firmware which is a real pain to learning. so this allows me to stop the code at the hardware level to give Upycraft a chance to reconnect at the sw level
However I get the following error
Ready to download this file,please wait!
………………
download ok
exec(open(‘micropython_six_segs-the-one.py’).read(),globals())
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
File “<string>”, line 7, in <module>
SyntaxError: ‘break’/’continue’ outside loop
If I comment out the line above as shown in above code and as shown below for reference in explaining with # it works but I need the if statement in the code so I start comparing values off the pot so I can set segments to extinguish in the display
#if (int(duty_cycle)) > 75:# if i comment this out works for pot and hw BUTTON reset i hooked up to force HW
What am i doing wrong, help is appreciated thanks RNT Team