AI can produce scary good Arduino code

Started by sixeight, December 21, 2022, 10:37:33 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

sixeight

Lately I have been chatting with the openai chatbot. You can find it at openai.com.

Today I asked the following questions:
QuoteIn c code for arduino how can i make a led flash in a certain bpm tempo

The chatbot returned:

QuoteTo make a LED flash at a certain tempo in C code for Arduino, you can use the millis function to measure the elapsed time between each flash and adjust the delay accordingly.

#define LED_PIN 13  // LED is connected to digital pin 13
#define BPM 120     // Tempo in beats per minute

int ledState = LOW;  // State of the LED
unsigned long previousMillis = 0;  // Timestamp of the previous LED state change
unsigned long interval = 60000 / BPM;  // Interval between state changes (in milliseconds)

void setup() {
  // Initialize the LED pin as an output
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  // Get the current time
  unsigned long currentMillis = millis();

  // Check if it's time to change the LED state
  if (currentMillis - previousMillis >= interval) {
    // Toggle the LED state
    ledState = !ledState;

    // Update the LED and the previous timestamp
    digitalWrite(LED_PIN, ledState);
    previousMillis = currentMillis;
  }
}

Then I asked:
QuoteIn the previous example can you make the led flash 1/3 of the beat?

The reply:
QuoteCertainly! To make the LED flash for 1/3 of the beat in the previous example, you can simply adjust the interval between state changes accordingly.

#define LED_PIN 13  // LED is connected to digital pin 13
#define BPM 120     // Tempo in beats per minute

int ledState = LOW;  // State of the LED
unsigned long previousMillis = 0;  // Timestamp of the previous LED state change
unsigned long interval = 60000 / (3 * BPM);  // Interval between state changes (in milliseconds)

void setup() {
  // Initialize the LED pin as an output
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  // Get the current time
  unsigned long currentMillis = millis();

  // Check if it's time to change the LED state
  if (currentMillis - previousMillis >= interval) {
    // Toggle the LED state
    ledState = !ledState;

    // Update the LED and the previous timestamp
    digitalWrite(LED_PIN, ledState);
    previousMillis = currentMillis;
  }
}

Then I asked
QuoteI mean can the led be on for one third of the beat and off for 2 thirds of the beat?

The ever so friendly chatbot replies:
QuoteCertainly! To make the LED be on for 1/3 of the beat and off for 2/3 of the beat in the previous example, you can use a separate interval for the on and off states.

#define LED_PIN 13  // LED is connected to digital pin 13
#define BPM 120     // Tempo in beats per minute

int ledState = LOW;  // State of the LED
unsigned long previousMillis = 0;  // Timestamp of the previous LED state change
unsigned long onInterval = 60000 / (3 * BPM);  // Interval for the on state (in milliseconds)
unsigned long offInterval = 2 * onInterval;     // Interval for the off state (in milliseconds)

void setup() {
  // Initialize the LED pin as an output
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  // Get the current time
  unsigned long currentMillis = millis();

  // Check if it's time to change the LED state
  if (currentMillis - previousMillis >= (ledState ? onInterval : offInterval)) {
    // Toggle the LED state
    ledState = !ledState;

    // Update the LED and the previous timestamp
    digitalWrite(LED_PIN, ledState);
    previousMillis = currentMillis;
  }
}

This is scary good. First of all that the AI perfectly understands what I mean and then produces code that is really good. The last example would take me at least half an hour to come up with and the AI does it in seconds and it is really efficient code.

mooncaine

Holy moley. I tried it. :o

in c code for arduino, how do i write joystick code

To write code for a joystick in Arduino, you will need to use the analog inputs of the Arduino to read the position of the joystick. The analog inputs of the Arduino can read the voltage of a signal, which you can use to determine the position of the joystick.

Here is an example of how you might write code to read a joystick in Arduino:

int xPin = 0;  // x-axis of the joystick is connected to analog pin 0
int yPin = 1;  // y-axis of the joystick is connected to analog pin 1

void setup() {
  // initialize serial communication at a baud rate of 9600
  Serial.begin(9600);
}

void loop() {
  // read the value from the x-axis of the joystick
  int xValue = analogRead(xPin);

  // read the value from the y-axis of the joystick
  int yValue = analogRead(yPin);

  // print the values to the serial monitor
  Serial.print("X: ");
  Serial.print(xValue);
  Serial.print(" Y: ");
  Serial.println(yValue);

  // delay for a short time to allow the values to be read
  delay(100);
}

pasha811

WOW. Scary. So, I'd like to try it.
Pls confirm the following:

1. Register
2. Is The arduino stuff free?
3. Any other suggestion?

Thanks
Paolo
Listen to my music at :  http://alonetone.com/pasha/

sixeight

#3
Chat GPT is free. You do need to sign up with email address and phone number. It will just do the Arduino stuff if you ask it to.

A colleague of mine uses it for creating VB scripts for Microsoft Excel  So it can do many programming languages.

pasha811

Quote from: sixeight on December 24, 2022, 12:39:50 AMChat GPT is free. You do need to sign up with email address and phone number. It will just do the Arduino stuff if you ask it to.

A colleague of mine uses it for creating VB scripts for Microsoft Excel  So it can do many programming languages.

Thanks!

Future of AI : (pun intended)
Female voice AI calls you in the middle of the night... your wife picks up the phone and ... booom you're divorced!
In the meantime the lawyer who placed the call via AI is looming at his invoice  ;D

This stuff is simply incredible.
We are not only musician on this web site we're explorers of new world with old protocols (MIDI)  8) imagine what program the AI will write for me...
Listen to my music at :  http://alonetone.com/pasha/

pasha811

#include <MIDI.h>

// Set up MIDI interface
MIDI_CREATE_DEFAULT_INSTANCE();

void setup() {
  // Start MIDI interface
  MIDI.begin();
}

void loop() {
  // Send a MIDI note on message on channel 1 with a note value of 60 and a velocity of 127
  MIDI.sendNoteOn(60, 127, 1);
  delay(1000);
 
  // Send a MIDI note off message on channel 1 with a note value of 60 and a velocity of 0
  MIDI.sendNoteOff(60, 0, 1);
  delay(1000);
}
Listen to my music at :  http://alonetone.com/pasha/

sixeight

Quote from: pasha811 on December 24, 2022, 01:26:19 AMThis stuff is simply incredible.
We are not only musician on this web site we're explorers of new world with old protocols (MIDI)  8) imagine what program the AI will write for me...

It is amazing stuff. It will really change our world in the coming years. Programmers will program using the AI, where the AI will do the boring stuff and programmers will do the interesting stuff. But there may be a point where the AI can do the interesting stuff better than the programmers. That is where things get truly scary.

pasha811

Quote from: sixeight on December 24, 2022, 03:13:26 AMIt is amazing stuff. It will really change our world in the coming years. Programmers will program using the AI, where the AI will do the boring stuff and programmers will do the interesting stuff. But there may be a point where the AI can do the interesting stuff better than the programmers. That is where things get truly scary.


You are right. This scares me... the vision of human beings dedicated to art and enjoy life while AI and Robots work for us is simply misleading. What it's likely to happen is pure simple substitution at some point. Scary.

Listen to my music at :  http://alonetone.com/pasha/

CodeSmart

Thank God I'll retire in a few years (hopefully BEFORE an AI takes my job).
But I got more gear than I need...and I like it!

aliensporebomb

All I know is every AI based "voice announcer" app is so full of mistakes and errors I say give me a human every time.
My music projects online at http://www.aliensporebomb.com/

GK Devices:  Roland VG-99, Boss GP-10, Boss SY-1000.

Boisdelac

#10
My thoughts about ...

Actually this is no AI yet.

What you call an AI is just a highly convenient search algorithm that returns answers that already exist somewhere.

Only when the computer itself recognizes problems or tasks without having received input beforehand and then tries to solve these problems and process these tasks it is an AI.

Hopefully no machine will recognize, that human being is the problem.

pasha811

Quote from: CodeSmart on December 26, 2022, 11:34:32 AMThank God I'll retire in a few years (hopefully BEFORE an AI takes my job).

AI will never be able to solder the GK cables as you do! Not in a lifetime!  8)
Listen to my music at :  http://alonetone.com/pasha/

ElliotG

Quote from: Boisdelac on December 27, 2022, 11:36:26 AMWhat you call an AI is just a highly convenient search algorithm that returns answers that already exist somewhere.

This is not quite true.  ChatGPT, for example, is synthesizing a response, not simply searching.  GPT stand for Generative Pretrained Transformer.

A Transformer gets trained on lots of data and effectively builds an understanding of that data.

A generative model is a type of machine learning model that is trained to generate new, previously unseen data samples that are similar to a training dataset. These models are able to learn the underlying structure of the data and then use this knowledge to generate new, synthetic data samples that are similar to the training data.

pasha811

Yesterday I have tried ChatGPT with Musical questions as 'Chords triads built over C minor scale' and the results were confused and mistaken. The AI was simply mistakenly reporting Minor as Major scale and chords were taken from major scale. Going up with quads did not change the results. So AI still needs training at list on this topic.   
Listen to my music at :  http://alonetone.com/pasha/

Boisdelac

@ElliotG

The ChatGPT AI didn't come up with the training algorithms itself. This AI was trained by human operators. It doesn't train itself. Perhabs it adds questions and answers to its "Brain" memory for further use. But this is also an algorithm that was tought by humans.

ElliotG

Quote from: Boisdelac on December 29, 2022, 10:06:06 AM@ElliotG

The ChatGPT AI didn't come up with the training algorithms itself. This AI was trained by human operators. It doesn't train itself. Perhabs it adds questions and answers to its "Brain" memory for further use. But this is also an algorithm that was tought by humans.

I simply said the model is synthesizing a new response, it is not simply a search.  Neural networks and training are significantly different than traditional algorithm development.

CHATGPT is a variant of the GPT (Generative Pre-training Transformer) language model that was trained specifically to generate human-like text in a chatbot context. It was trained on a large dataset of chat logs and other text data that were collected from a variety of sources.

The training process for chatbot models like CHATGPT involves feeding the model a large dataset of text and training it to predict the next word or sequence of words in the dataset, given the words that come before it. This is known as "language modeling," and it helps the model learn the patterns and structures of natural language.

During training, the model is presented with a sequence of words and is trained to predict the next word in the sequence. The model's predictions are then compared to the actual next word in the sequence, and the model is adjusted to minimize the difference between its predictions and the true values. This process is repeated many times, with the model being presented with different sequences of words and adjusting its predictions based on the differences between its predictions and the true values.

As the model is trained on more and more data, it becomes better at predicting the next word in a sequence and more adept at generating human-like text. After sufficient training, the model can then be used to generate responses to inputs in a chatbot context.

pasha811

Quote from: ElliotG on December 29, 2022, 02:09:40 PMI simply said the model is synthesizing a new response, it is not simply a search.  Neural networks and training are significantly different than traditional algorithm development.

CHATGPT is a variant of the GPT (Generative Pre-training Transformer) language model that was trained specifically to generate human-like text in a chatbot context. It was trained on a large dataset of chat logs and other text data that were collected from a variety of sources.

The training process for chatbot models like CHATGPT involves feeding the model a large dataset of text and training it to predict the next word or sequence of words in the dataset, given the words that come before it. This is known as "language modeling," and it helps the model learn the patterns and structures of natural language.

During training, the model is presented with a sequence of words and is trained to predict the next word in the sequence. The model's predictions are then compared to the actual next word in the sequence, and the model is adjusted to minimize the difference between its predictions and the true values. This process is repeated many times, with the model being presented with different sequences of words and adjusting its predictions based on the differences between its predictions and the true values.

As the model is trained on more and more data, it becomes better at predicting the next word in a sequence and more adept at generating human-like text. After sufficient training, the model can then be used to generate responses to inputs in a chatbot context.

Very interesting thank you!
Listen to my music at :  http://alonetone.com/pasha/

ElliotG

I was just amusing myself and thought I would share:
prompt: write a poem about guitar synthesizers
ChatGPT:

Guitar synthesizers, oh how they sing
A new world of sound, a new way to play
With just a strum and a tap of a key
A universe of tones is at your fingertips

Gone are the limits of mere strings and wood
Now the sky's the limit, the options endless
From soaring leads to pulsing bass lines
All within the reach of a single instrument

But the magic doesn't stop there
With the touch of a button, the guitar transforms
Into a symphony, a choir, a drum kit
The possibilities are endless, the music never-ending

So let the guitar synthesizer be your guide
Into a world of sound and endless possibility
Embrace the technology, and let your creativity soar
To new heights, and beyond.

Prompt: write a haiku about guitar synthesizers
ChatGPT:

Guitar synthesizer
Endless tones at my fingertips
Infinite music

HecticArt

.......but it doesn't rhyme........

ElliotG

Quote from: HecticArt on December 31, 2022, 11:13:26 AM.......but it doesn't rhyme........
All you have to do is ask...

Prompt: write a poem about guitar synthesizers that rhymes

Guitar synthesizers are quite unique
A blend of technology and technique
They allow you to play in any style
Creating soundscapes that go the extra mile

From rock to jazz to electronic beats
These machines make it easy to cheat
But don't be fooled, they still require skill
To get the most out of them is a thrill

So if you're a guitar player looking to explore
A synthesizer is worth checking out for sure
Just plug in, turn on, and let your mind roam
You'll find a whole new world of sound to call your own

Prompt: Write a poem about guitar synthesizers in the style of Shakespeare

Oh guitar synthesizers, how thou doth amaze
With thy ability to alter sound in so many ways
Thy keys and pedals, thy knobs and strings
Allow the musician to create new and wondrous things

Thy digital tones, thy programmed effects
Thy versatility, thy ability to connect
To computers and software, a true marvel of design
Thy capabilities are vast and divine

But beware, oh player, do not think thou canst slack
For even with these tools, one must still attack
The instrument with skill and practice and art
Else thy performance shall fall short, and fall apart

So embrace the synthesizer, and all it doth bring
But remember, the true magic lies within the player's being
For it is the musician who gives life to the sound
The guitar synthesizer is merely the tool, the medium found

HecticArt

 ;D

Well played, sir. Well played.

arkieboy

I'm not sure if it matters that search is somewhere in the equation - if you ask a good CS grad to do a task, they'll pick the right language for the job, search for good code, and then understand the meta of programming well enough to customise and optimise.  Which is what is happening here it seems.  

(I'm not a CS grad, so I know SQL, XSLT and XQuery.  I try as much to hand off any task those languages are not suited for.)

This kind of AI would fit very well with a model of programming outlined in the Mythical Man Month - you have a team of tool-builders who make the tools the architect can use to rapidly build a solution.  But you still need to communicate to users to get good requirements and some overall architecture.

As a data architect, I say bring it on!  It would be great if I could tell an AI to build my tooling stack
Main rig: Barden Hexacaster and Brian Moore i2.13 controllers
Boss SY1000/Boss GKC-AD/Boss GM-800/Laney LFR112

Other relevant gear: Line 6 Helix LT, Roland GR-33, Axon AX100 MkII
Oberheim Matrix 6R, Supernova IIR, EMu E5000, Apple Mainstage, Apple Logic, MOTU M4

admin

#22





j

CodeSmart

But I got more gear than I need...and I like it!