Announcement

Collapse
No announcement yet.

Single oder Doppel Variable deklarieren / declare Single or Double Variable

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Single oder Doppel Variable deklarieren / declare Single or Double Variable

    Hallo Leute,
    wie erstelle ich ein Single oder Dopple Variable? Ich möchte eine Spannung messen. Dafür brauche ich eine Variable mit Nachkomme stelle, um Faktor und Spannung genau zu berechnen.

    ----- Formel ------
    Code:
    Faktor = 3,3V / 255
        ^-------------------- Single- oder Double- Variable
    
    Spannung = ADC_8 x Faktor
                          ^-------------------- Single- oder Double- Variable
                  ^-------------------- GPIO1 als 8-Bit ADC
         ^-------------------- Single- oder Double- Variable
    ------------------- ENGLISH --------------------------------------------------------------------------------

    Hi guys,
    how do I create a single or double variable? I want to measure a voltage. For this I need a variable with a descendant place to calculate the factor and voltage exactly.

    ----- Formula -----
    Code:
    Factor = 3.3V / 255
    ^-------------------- Single- or Double- Variable
    
    Voltage = ADC_8 x factor
                        ^-------------------- Single- or Double- Variable
                 ^-------------------- GPIO1 as 8-Bit ADC
        ^-------------------- Single- or Double- Variable
    Last edited by Patrick Dreger; 29 June 2021, 06:51 PM. Reason: Kommentare einrücken

  • #2
    Hi,

    I'm not sure I understand your inquiry. Would you be able to explain it differently?

    You might want to show us code snippets from C/C++ that we could us understand what it is that you meant so we could help you try and implement the same in 4DGL.

    Best Regards

    Comment


    • #3
      Okay

      Code Example with BSCOM-AVR
      Code:
      ...
      Dim Factor As Single    'Single-Variable
      Dim Voltage As Single  'Single-Variable
      Dim GOI1 As Byte       ' Byte-Variable
      
      Main:
         Factor = 3.3 / 255   ' 0,0129...
         do
            GIO1 = GetADC(1)   ' Read ADC-Signal
            Voltage = factor * GIO1
      
            Print "Voltage: " ; Voltage   ' Output voltage
            waitms 500   ' wait 500 ms
         loop
      
      Return
      Code Example with Adruino C++
      Code:
      void loop() {
      
         float Factor;
         float Voltage;
         byte adc;
      
         Factor = 3.3 / 255;
      
         while()
         {
            adc = analogRead(IO1);
            Voltage = Factor * adc;
            printf("Voltage : %d",Voltage);
            pause(500);
         }
      }

      Comment


      • #4
        Hi,

        You can declare variables in 4DGL as shown below:

        Code:
        // 32-bit value (array of 2 16-bit variables)
        // for float values
        var Factor[2];
        var Voltage[2];
        
        // 16-bit variable
        var adc; // if you need an 8-bit value simply ignore the high byte
        Also, I noticed that you opened this topic for Goldelox displays. There is no internal function for performing float calculations in Goldelox displays. You might want to check out Diablo16 displays instead.

        Best Regards

        Comment


        • #5
          Hallo,
          ich habe erstmal mein Programm so geschrieben. Nicht wundern, die Variablen sind auf Deutsch (Spannung = Voltage).
          Ich habe extra GOLDELOX genommen, weil mein erstes Display zum Testen gekauft habe. Ich besitze noch 2 verschiedene Modellen. Um nur eine Spannung zu messen, ist diese Produkt ausreichend.
          Es hätte sein können das ich zu dumm bin eine Variable mit Kommastellen zu erstellen.

          ------------------------ Englisch ------------------------------------

          I have written my program like this. Don't be surprised, the variables are in German (Spannung = Voltage).
          I took extra GOLDELOX, because I bought my first display for testing. I still own two different models. To measure only one voltage, this product is sufficient.
          It could have been that I am too stupid to create a variable with decimal places.


          Code:
          func main()
             // Uncomment the following if uSD images, fonts or strings used.
             var Spannung_h;
             var Spannung_l;
             var Spannung;
             var buffer;
          
             print("Starting\n") ;
             while(!media_Init())
                putstr("Drive not mounted...");
                pause(200);
                gfx_Cls();
                pause(200);
             wend
             // Form1 1.2 generated 06.07.2021 09:05:00
             gfx_BGcolour(0xDF5F) ;
          
             pin_Set(ANALOGUE_8,IO1);
             pin_Set(INPUT,IO2);
          
             gfx_Cls();
             txt_Set(TEXT_COLOUR, 0);
             txt_Set(TEXT_HIGHLIGHT,0xDF5F);
          
             repeat
                txt_MoveCursor(1,1);
                Spannung := pin_Read(IO1) * 129;
                Spannung_h := Spannung / 10000;
                buffer := Spannung_h *10000;
                Spannung_l := Spannung - buffer;
          
                if(pin_Read(IO2) == 0)
                   Spannung_h := Spannung_h * 2;
                   Spannung_l := Spannung_l * 2;
                   if(Spannung_l >= 10000)
                      Spannung := Spannung_l / 10000;
                      Spannung_h := Spannung_h + Spannung;
                      Spannung := Spannung * 10000;
                      Spannung_l := Spannung_l - Spannung;
                   endif
                endif
          //-------------------------------------------------------------------
                txt_MoveCursor(3,1);
                txt_Set(TEXT_WIDTH,2);
                txt_Set(TEXT_HEIGHT,2);
                print(Spannung_h,",");
                txt_Set(TEXT_WIDTH,2);
                txt_Set(TEXT_HEIGHT,2);
                if(Spannung_l < 10)
                   print("000");
                else if(Spannung_l < 100)
                   print("00");
                else if(Spannung_l < 1000)
                   print("0");
               endif
               txt_Set(TEXT_WIDTH,2);
               txt_Set(TEXT_HEIGHT,2);
               print (Spannung_l,"V \n");
                pause(500);
             forever
          endfunc
          Last edited by Patrick Dreger; 6 July 2021, 06:33 PM. Reason: Anzeigefehler-> Null-Stellen eingefügt werden

          Comment


          • #6
            Hi Patrick,

            I'm glad you figured that out.

            I suggested float variables and functions from Diablo16 since you provided an Arduino example which uses float.

            If you think Goldelox is sufficient for your needs, then feel free to use it at its fullest.

            If you have other inquiries, please don't hesitate to contact us again.

            Best Regards

            Comment

            Working...
            X