ChatGPT Writes BS2 Code
The new AI ChatGPT is off to a scary good start. I saw a post where it generated some Picaxe code. So I asked it: "Write BASIC stamp 2 code to constantly read a photocell and show the value on a DEBUG screen." Nothing more.
It replied:
Here is some sample code for a BASIC Stamp 2 that constantly reads a photocell and displays the value on the DEBUG screen:
' Constantly read photocell and display value on DEBUG screen DEBUG "Starting photocell reading loop", CR ' display message on DEBUG screen photocellPin VAR Pin ' define photocell pin LOOP: DEBUG "Photocell value: ", DEC photocellPin, CR ' read value of photocell and display onDEBUG screen PAUSE 1000 ' wait 1 second before next reading GOTO LOOP ' repeat loop
Note that this code assumes that the photocell is connected to a specific pin on the BASIC Stamp 2, which should be specified in the photocellPin VAR Pin line. Also, you may want to adjust the value of the PAUSE command to suit your needs.
WOW! Not bad, comments and all! It didn't know about RCtime. Supposedly it learns and gets better with the volume of inquiries. We're way past Eliza now, huh?
Comments
Analog in on a BS2 via ChatGPT:
The BASIC Stamp 2 does not have built-in analog-to-digital conversion (ADC) capability. However, there are ways to add this functionality to the BASIC Stamp 2 by using external components such as an Analog-to-Digital Converter (ADC) chip
One way to read an analog input such as a photocell with a Basic Stamp 2 is to use a voltage divider circuit that connects the photocell to a digital pin and a fixed resistor. The voltage at the digital pin will be proportional to the resistance of the photocell. The Basic Stamp 2 can then read the voltage on the digital pin using the pulsein command, and convert it to a resistance value
Here is an example of BASIC Stamp 2 code that uses a voltage divider circuit to read the value of a photocell connected to pin A0 and displays the value on the DEBUG screen_
This code uses the pulsein command to measure the voltage on pin A0 and stores it in the variable voltage. The high command sets the pin A0 to high, and the pulsein command measures the time it takes for the pin A0 to go low after setting it high. This time value is proportional to the voltage value.
Then we convert the voltage to resistance using a fixed ratio, in this case it's 10. The resistance value is stored in the variable resistance. The debug command is then used to display the value of resistance on the DEBUG screen. The pause 1000 command creates a delay of 1 sec so that the value can be read and displayed properly. The code then loops back to the beginning of the main routine using the goto command, allowing the photocell value to be constantly read and displayed.
It's important to note that you can adjust the fixed ratio and the pause time to your liking, and you can also add more functionality or conditionals to the code as per your use-case.
its a bomb AI man:)
Interesting. In fact I'd say the code that the program created looks almost as good as what I'd expect from someone with short experience time with a Stamp.
Two mascots present with stares.