Menu

Using ChatGPT or Claude to help with GCBASIC development

2026-06-02
2026-06-02
  • Fabrice Engel

    Fabrice Engel - 2026-06-02

    Dear GCBASIC Community,

    I just wanted to report my positive experience by using AI LLM tools like ChatGPT and Claude to support me by the development of my latest project source code.

    It is to operate a fluid detection system using a photosensor. The whole code is 800 lines big (and I not count all comments inside), and I assume that between 80% to 90% was fully generated by the combination of both LLM mentioned previously. The generated code is strong, work very well and let me win weeks and weeks of hobbyst development periods.

    I also learned that some nice syntax in GCBASIC are possible like:

    outputCounter++                              // Using just ++, I use <variable> += 1
    
    If outputState = STATE_EMPTY  Then EventCode = EVENT_EMPTY  // In one line without End If
    
    HSerPrint "PWM="  : HSerPrint PWMLedDefined      // Using <:> to separate
    

    I am always struggeling with langage syntax and that is the reason why I never learned C++, I was so happy to discover GCBASIC for doing something with microcontrollers. Thank to the whole Team behind.

    To give you an idea of the hardware used, please check both pictures. The project uses a PIC16F1825.

    See also an example (sorry it is in French, but source code comments in English) how I interact with Claude, and how a non blocking Buzzer routine was generated by Claude. First compilation, 0 errors and work as expected - good :)

    La solution : une machine d'état non-bloquante similaire à ServiceBuzzer(), appelée ServiceConfirmFeedback().
    Elle -assertera LedRed et Buzzer à chaque itération de boucle pendant la phase ON, ce qui surpasse UpdateOutput() puisqu'elle s'exécute après.
    
    Nouvelles constantes à ajouter
    #DEFINE CONFIRM_FEEDBACK_ON  = 2   // ON duration per blink:  2 * 50ms = 100ms
    #DEFINE CONFIRM_FEEDBACK_OFF = 2   // OFF duration per blink: 2 * 50ms = 100ms
    
    Nouvelles variables globales à ajouter
    // Non-blocking confirm feedback state machine
    Dim confirmFeedbackActive  As Bit   // 1 = feedback sequence is running
    Dim confirmFeedbackState   As Bit   // 1 = ON phase (LED+buzzer on), 0 = OFF phase
    Dim confirmFeedbackCount   As Byte  // Remaining blinks/beeps to produce
    Dim confirmFeedbackTick    As Byte  // BuzzerTick snapshot at last phase transition
    Dim confirmFeedbackElapsed As Byte  // Elapsed ticks since last phase transition
    
    Nouvelles initialisations à ajouter
    confirmFeedbackActive = 0           // No feedback running at startup
    confirmFeedbackState  = 0           // Start in OFF phase
    confirmFeedbackCount  = 0           // No blinks pending
    confirmFeedbackTick   = 0           // Tick reference cleared
    
    CycleConfirmLevel()  version non-bloquante
    // ----------------------------------------------------------
    // CycleConfirmLevel
    // Advances confirm level: 12...81 (wraps around)
    // Updates outputConfirm immediately for the running loop
    // Resets persistence counter to avoid stale accumulated count
    // Saves new level index to EEPROM
    // Launches non-blocking N-blink + N-beep feedback sequence
    // A new button press while feedback runs restarts it cleanly
    // ----------------------------------------------------------
    Sub CycleConfirmLevel()
        confirmLevel++                                   // Advance to next level index
    
        If confirmLevel > CONFIRM_MAX Then               // Wrap around after level 8
            confirmLevel = CONFIRM_MIN                   // Back to level 1 (100 iterations)
        End If
    
        outputConfirm = confirmLevel * CONFIRM_STEP      // Apply new threshold immediately
        outputCounter = 0                                // Reset persistence: restart counting
    
        Call SaveConfirmLevel()                          // Persist new index to EEPROM
    
        // Launch non-blocking N-blink + N-beep feedback
        // Disabling ServiceBuzzer prevents Buzzer conflict during feedback
        BuzzerEnable          = 0                        // Suspend any running buzzer sequence
        Buzzer                = 0                        // Ensure clean buzzer start state
        LedRed                = 0                        // Ensure clean LED start state
        confirmFeedbackCount  = confirmLevel             // N blinks = selected level index
        confirmFeedbackTick   = BuzzerTick               // Capture current tick as start reference
        confirmFeedbackState  = 1                        // Begin with ON phase immediately
        confirmFeedbackActive = 1                        // Enable the feedback service routine
        LedRed                = 1                        // First blink: LED on immediately
        Buzzer                = 1                        // First beep: buzzer on immediately
    End Sub
    
    Nouvelle sous-routine ServiceConfirmFeedback()
    // ----------------------------------------------------------
    // ServiceConfirmFeedback
    // Non-blocking N-blink + N-beep feedback for confirm level change
    // Must be called AFTER UpdateOutput() and ServiceBuzzer() in main loop
    // Re-asserts LedRed and Buzzer each iteration during ON phase,
    // overriding UpdateOutput() since it runs after it
    // BuzzerEnable=0 prevents ServiceBuzzer() from interfering with Buzzer
    // A new button press restarts the sequence cleanly via CycleConfirmLevel()
    // ----------------------------------------------------------
    Sub ServiceConfirmFeedback()
        If confirmFeedbackActive = 0 Then                // No feedback running: nothing to do
            Exit Sub
        End If
    
        confirmFeedbackElapsed = BuzzerTick - confirmFeedbackTick  // Ticks since last phase change
    
        If confirmFeedbackState = 1 Then                 // Currently in ON phase (LED + buzzer active)
            LedRed = 1                                   // Re-assert every iteration: override UpdateOutput
            Buzzer = 1                                   // Re-assert every iteration: keep buzzer on
    
            If confirmFeedbackElapsed >= CONFIRM_FEEDBACK_ON Then  // ON duration elapsed?
                LedRed               = 0                 // Turn off LED
                Buzzer               = 0                 // Turn off buzzer
                confirmFeedbackState = 0                 // Switch to OFF phase
                confirmFeedbackTick  = BuzzerTick        // Record OFF phase start time
            End If
    
        Else                                             // Currently in OFF phase (LED + buzzer off)
            If confirmFeedbackElapsed >= CONFIRM_FEEDBACK_OFF Then // OFF duration elapsed?
                confirmFeedbackCount--                   // Count this completed blink
    
                If confirmFeedbackCount = 0 Then         // All N blinks done?
                    confirmFeedbackActive = 0            // Stop feedback sequence
                    LedRed               = 0            // Ensure LED is off
                    Buzzer               = 0            // Ensure buzzer is off
                    Exit Sub                            // Done
                End If
    
                // More blinks remaining: start next ON phase
                LedRed               = 1                // LED on for next blink
                Buzzer               = 1                // Buzzer on for next beep
                confirmFeedbackState = 1                // Enter ON phase
                confirmFeedbackTick  = BuzzerTick       // Record ON phase start time
            End If
        End If
    End Sub
    
    Modification de la boucle principale
    
    Ajouter ServiceConfirmFeedback() après ServiceBuzzer() et avant ServiceHeartbeat() :
    
    Call UpdateOutput()                  // Apply persistence filter; drive pump and LEDs
    Call ProcessEvents()                 // Translate event code into buzzer pattern
    Call ServiceBuzzer()                 // Execute non-blocking buzzer sequence
    Call ServiceConfirmFeedback()        // Execute non-blocking N-blink/beep confirm feedback
    Call ServiceHeartbeat()              // Manage blue LED heartbeat (system alive indicator)
    
    Pourquoi ça fonctionne sans bloquer
    
    Mécanisme   Explication
    Pas de Wait La routine retourne immédiatement si le tick n'a pas changé
    -assertion chaque itération   Pendant la phase ON, LedRed=1 et Buzzer=1 sont réécrits après UpdateOutput()
    Priorité par ordre d'appel  ServiceConfirmFeedback() s'exécute après UpdateOutput()  sa valeur est la dernière écrite
    Appui rapide    Un nouvel appui pendant le feedback relance CycleConfirmLevel() qui réinitialise proprement la machine d'état
    
     

    Last edit: Fabrice Engel 2026-06-02
  • Anobium

    Anobium - 2026-06-02

    Great to hear.

    The source for this AI? The demonstrations ojn GitHub, the extensive Help and this Forum.


    I use Claude! it is better and faster then me coding it!

     
    • Fabrice Engel

      Fabrice Engel - 2026-06-02

      I have started with ChatGPT and complete with Claude. I have no commercial API only free versions, so I worked on the project step by step as soon I received few tokens to continu :)

      AI Claude provide much better code, but ChatGPT explained more the background and how technically the whole PWM -> Analog -> Led // Phototransistor -> ADC Reading work together. I have a lot of conversationnel pages with ChatGPT to obtain a final result.

      Once having a fully code, I have asked Claude to make a final pass, find dead variables even routines, add on every line a comment in English, check if code can be optimised and make proposals.

      I am really happy with the result, but I am not ready yet to share the project. KiCad source are not polished, and I had still need to do some afterwork.

      In the meantime, if someone have a particular related question, just ask here :) Thank

       

      Last edit: Fabrice Engel 2026-06-03

Log in to post a comment.

Auth0 Logo