Shop OBEX P1 Docs P2 Docs Learn Events
ChatGPT Writes BS2 Code — Parallax Forums

ChatGPT Writes BS2 Code

ercoerco Posts: 20,256
edited 2023-01-25 07:57 in General Discussion

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?

https://chat.openai.com/chat

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_

    main:
       high A0        'set the pin A0 to high
       let voltage = pulsein(A0,1) ' measure the voltage on the pin A0
       let resistance = voltage * 10 ' convert the voltage to resistance using a fixed ratio
       debug resistance ' Display the resistance value on the DEBUG screen
       pause 1000      ' wait for 1 sec
       goto main       ' loop back to the beginning of the main routine
    

    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:)

  • @ozzy92 said:
    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.

Sign In or Register to comment.