B4R Question array of floats from C to B4R

peacemaker

Expert
Licensed User
Longtime User
Hi, All

How to get to B4R an array of floats ?
"pixels" array from this sketch below:

Arduino sketch:
#include <Wire.h>
#include <Adafruit_AMG88xx.h>

Adafruit_AMG88xx amg;
float pixels[AMG88xx_PIXEL_ARRAY_SIZE];

void setup() {
    Serial.begin(9600);
    bool status;
   
    // default settings
    status = amg.begin();
    if (!status) {
        Serial.println("Could not find a valid AMG88xx sensor, check wiring!");
        while (1);
    }
    delay(100); // let sensor boot up
}


void loop() {
    //read all the pixels
    amg.readPixels(pixels);

    //delay a second
    delay(1000);
}
 

peacemaker

Expert
Licensed User
Longtime User
SOLVED:

B4X:
Sub Process_Globals
    Public Serial1 As Serial
    Public pixels(64) As Float
    Dim tim As Timer
    Public AVG As Float
End Sub

Private Sub AppStart
    Serial1.Initialize(256000)
    Log(CRLF + "AppStart")
    tim.Initialize("tim_Tick", 1000)
    tim.Enabled = True
End Sub

Sub tim_tick
    RunNative("getPixels", Null)
    Dim av As Float, count As Int
    For i = 0 To pixels.Length - 1
        av = av + pixels(i)
        count = count + 1
    Next
    AVG = av / count
    Log("AVG temperature = ", AVG)
End Sub

#if C
#include <Wire.h>
#include <Adafruit_AMG88xx.h>

Adafruit_AMG88xx amg;
float pixels[AMG88xx_PIXEL_ARRAY_SIZE];

void getPixels(B4R::Object* u) {
    amg.begin();
    delay(100); // let sensor boot up
    //read all the pixels
  
    amg.readPixels((float*)b4r_main::_pixels->data);

    //delay a second
    delay(1000);
}
#End If
 
Last edited:
Upvote 0
Top