Jeremy Leach
Senior Member
Hi,
It's been a very long time since I avidly posted here, but I've recently had a little project on the go for an unusual van hear, and I was drawn back to the ease of use of the PICAXE .
As I'm very rusty on syntax and have lately been getting into AI in a big way, I thought I'd just tell ChatGPT what I wanted, that I was using an 08M, what my pinout needs to be, and just let it get on with it ! I'm very impressed that it has quite a deep understanding of PICAXEs and the code it spewed out is below. But I've had to tweak it a little because :
1. It omitted dirsC, so didn't specify the inputs and outputs - not good !
2. It originally thought it ok to use w0 and b0 as if they were completely separate variables - it didn't understand the nuance that b0 is part of w0. A pretty fundamental blooper.
I've told it off over these issues so hopefully it'll learn (I'm not exactly sure how it learns from user input though, but I'm guessing it must do). I'm just interested if anyone else has used AI to generate code and thought I'd share my experience.
It's been a very long time since I avidly posted here, but I've recently had a little project on the go for an unusual van hear, and I was drawn back to the ease of use of the PICAXE .
As I'm very rusty on syntax and have lately been getting into AI in a big way, I thought I'd just tell ChatGPT what I wanted, that I was using an 08M, what my pinout needs to be, and just let it get on with it ! I'm very impressed that it has quite a deep understanding of PICAXEs and the code it spewed out is below. But I've had to tweak it a little because :
1. It omitted dirsC, so didn't specify the inputs and outputs - not good !
2. It originally thought it ok to use w0 and b0 as if they were completely separate variables - it didn't understand the nuance that b0 is part of w0. A pretty fundamental blooper.
I've told it off over these issues so hopefully it'll learn (I'm not exactly sure how it learns from user input though, but I'm guessing it must do). I'm just interested if anyone else has used AI to generate code and thought I'd share my experience.
Code:
symbol thermalSwitch = pinC.4 ' Input from thermal switch (e.g., physical pin 4 on 08M2)
symbol relayOutput = C.2 ' Output to the TIP31C (e.g., physical pin 5 on 08M2)
symbol ledOutput = C.1 ' Output to the LED (e.g., physical pin 6 on 08M2)
symbol failsafeTriggered = b0 ' Flag to track the failsafe state (0 = normal, 1 = failsafe)
symbol aliveCounter = b1 ' Timer variable for "I'm alive" flash
dirsC = %00000110 ' Set C.2 and C.1 as outputs, others as inputs
high relayOutput ' Start with relay de-energized (heater ON by default)
low ledOutput ' Ensure LED is off initially
failsafeTriggered = 0
gosub startupFlash ' Flash the LED at startup
main:
do
if thermalSwitch = 1 and failsafeTriggered = 0 then
gosub activateFailsafe ' Trigger the failsafe if the thermal switch opens
endif
if failsafeTriggered = 1 then
gosub alertFailsafe ' Activate LED and buzzer in failsafe state
else
gosub aliveFlash ' Perform the "I'm alive" flash
endif
pause 100 ' Small delay for loop stability
loop
startupFlash:
for b1 = 1 to 3 ' Flash LED 3 times at startup
high ledOutput ' Turn LED ON
pause 200 ' Keep LED ON for 200ms
low ledOutput ' Turn LED OFF
pause 200 ' Keep LED OFF for 200ms
next b1
return
activateFailsafe:
failsafeTriggered = 1 ' Set failsafe state
low relayOutput ' Energize the relay to turn OFF the heater
return
alertFailsafe:
high ledOutput ' Turn LED ON
pause 500 ' Keep LED ON for 500ms
low ledOutput ' Turn LED OFF
pause 500 ' Keep LED OFF for 500ms
return
aliveFlash:
aliveCounter = aliveCounter + 1 ' Increment the counter
if aliveCounter >= 50 then ' ~5 seconds (50 x 100ms loop pauses)
high ledOutput ' Brief flash of LED
pause 100 ' Keep LED ON for 100ms
low ledOutput ' Turn LED OFF
aliveCounter = 0 ' Reset counter
endif
return