drewzero1 wrote: Tue Jan 16, 2024 12:58 pm
ge_rik wrote: Tue Jan 16, 2024 11:47 am
Im not clear how GPT Chat assists with coding. Does it write the code or check the code after you've written it?
Rik
It can be used to write the code (
Github Copilot for example) but I have also recently heard that it might be able to
'translate' existing programs from one language or library to another equivalent one. Given these language models'
propensity to just make up convincing facts when they don't really know the answer, I'd trust their programming about as far as I could throw it.
ChatGPT will write code for a specific language in answer to question - obviously the more precise the question the better the code provided. But, as Drew noted - its best to be cautious before committing to the answers provided. However, so far, it has provided workable code for the things I have tried to do. It does more than a compiler, i.e it will generate code rather than simply checking the syntax and structure. As a simple example:
I asked ChatGPT the equivalent of “Hello World” as in “ Provide arduino code to turn on led on pin 4”
The code returned was:
==>
const int ledPin = 4; // Define the pin number for the LED
void setup() {
pinMode(ledPin, OUTPUT); // Set the LED pin as an output
}
void loop() {
digitalWrite(ledPin, HIGH); // Turn on the LED
delay(1000); // Wait for 1 second
digitalWrite(ledPin, LOW); // Turn off the LED
delay(1000); // Wait for 1 second
}
<==
It also provides a short explanation
==>
This code sets up pin 4 as an output, then in the loop function, it turns the LED on for 1 second and off for 1 second in a continuous loop. Connect the positive leg of the LED to pin 4 and the negative leg to ground.
<==
More complex questions result in more code and thus greater need to understand what it is returning.