USE AI (DEEPSEEK) for programming

Place code snippets and demo code here
Post Reply
efalken
Posts: 66
Joined: Tue Mar 02, 2021 3:47 pm
Has thanked: 38 times
Been thanked: 42 times

USE AI (DEEPSEEK) for programming

Post by efalken »

Recently I've tried some AI programming tools.
This time I came across Deepseek. I gave some simple prompts an could easily get working web apps and python projects.
Then I gave Annex-code a try.
I copied a working project file (ESP8266 with TM1638 module and piezo speaker) I use for several IoT devices over MQTT.
When asking to analyze the code the AI came up with clever WORKING optimizations and commented the code completly.
Inspired by this, I just asked to program a simple syntheziser with the obove setup.
And it worked INSTANTLY.
From now on I will allways start my projects with this approach.
Here is the code the AI produced.
TRY it yourself!

Code: [Local Link Removed for Guests]

'****************************************************
'** Synthesizer with Keyboard Input
'** Simulates a simple keyboard with 8 keys
'** Tones are two octaves higher (C6 to C7)
'** Note values (without octave) are displayed centered on the screen
'** Current time is displayed when no button is pressed
'****************************************************

'** Hardware Initialization
TM1638.SETUP 14, 12, 13  'Initialize TM1638 module (data pin, clock pin, strobe pin)
PIN.MODE 4, OUTPUT        'Configure pin 4 for audio output

'** Frequencies for the keys (in Hz)
'** Two octaves higher: C6 (1047 Hz) to C7 (2093 Hz)
DIM NOTES(8) = 1047, 1175, 1319, 1397, 1568, 1760, 1976, 2093  'C6, D6, E6, F6, G6, A6, B6, C7

'** Note values without octave for display
DIM NOTEN$(8) = "  C  ", "  D  ", "  E  ", "  F  ", "  G  ", "  A  ", "  B  ", "  C  "

'** Main Program Loop
DO
  '** Read button status
  A = TM1638.BUTTONS

  '** Play a tone if a key is pressed
  IF A > 0 THEN
    '** Determine which key is pressed (0 to 7)
    FOR I = 0 TO 7
      IF (A AND (1 << I)) > 0 THEN
        '** Set tone frequency based on the key
        FREQ = NOTES(I)
        '** Play the tone
        PIN.TONE 4, FREQ, 100  'Play tone for 100 ms
        '** Display the pressed note (centered) on the screen
        TM1638.PRINT NOTEN$(I), 3
        EXIT FOR  'Exit loop once a key is found
      END IF
    NEXT I
  ELSE
    '** No key pressed: Display the current time
    CURRENT_TIME$ = LEFT$(TIME$, 2) + ":" + MID$(TIME$, 4, 2)  'Format as HH:MM
    TM1638.PRINT CURRENT_TIME$, 3  'Display the time
  END IF

  '** Short pause to slow down the loop
  PAUSE 50
LOOP
User avatar
karlkloss
Posts: 124
Joined: Fri Aug 18, 2023 12:21 pm
Has thanked: 21 times
Been thanked: 14 times

Re: USE AI (DEEPSEEK) for programming

Post by karlkloss »

My experiences with AI generated code have been very mixed so far.

To give an example, I needed an RP2040 (Raspi Pico) to output a 24MHz clock, to drive an external circuit.
I asked several AIs to generate code for that, and all of them generated code that uses the PIO to generate that signal.

While the codes all looked good at the first glance, none of them worked.

So I took a dive into the datasheet, and found a solution where I just configure the internal prescaler to route half of the USB clock (48MHz) to a port pin. One line of code, permanent clock output without the processor doing anything.

I don't think that AI will take over my job soon.
User avatar
PeterN
Posts: 610
Joined: Mon Feb 08, 2021 7:56 pm
Location: Krefeld, Germany
Has thanked: 290 times
Been thanked: 341 times
Contact:

Re: USE AI (DEEPSEEK) for programming

Post by PeterN »

Good morning.

My experience with AI confirms that the current language models only gain their information by reading and limited interpretation of the content created by humans. The "known" programming languages have left a lot of traces on the web. Annex has not done that ... not yet;-) However, it stands out from the old BASIC due to some valued special features - which are unknown to the AIs.
Even my test-like approach of using the Annex help file and parts of the forum as input for notebook.lm could not "convince" this AI to use this source verbatim - for example, it vehemently insisted on using WAIT and not PAUSE and was reluctant to be convinced of the actual function of WAIT.
Your use of the clock signal also goes (for a while) beyond the capabilities of today's language models. A sign of applied human intelligence? ;-)
efalken
Posts: 66
Joined: Tue Mar 02, 2021 3:47 pm
Has thanked: 38 times
Been thanked: 42 times

Re: USE AI (DEEPSEEK) for programming

Post by efalken »

You are right, it is not a self driving car yet. Always good to know what you are doing. But ignoring this tool would be a mistake. I throw any Error messages back on the AI and often get an insightfull response, that teaches me a lot. It's a tool but very powerful.
Post Reply