Regards
I have this problem, I have simulated a sine wave using the for loop and the sin() function, inside the void loop, I am showing it on a 1.8" tft screen, but I noticed when printing by serial the millis() function slows down , the function of this code is to execute and simulate the wave all the time in the loop and display it on the tft screen. How could I replace the for loop and use another way to prevent time from slowing down. Thanks
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#define TFT_DC 8
#define TFT_CS 10
#define TFT_RST -1
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
float j = 2 * 3.1416 / 360 ;
byte n = 1 ;
byte fase = 0 ;
void setup()
{
Serial.begin(9600);
tft.initR(INITR_GREENTAB); //
tft.fillScreen(ST7735_BLACK);
tft.setRotation(3);
}
void loop() {
for ( long i = 0 ; i < 2200; i++)
{
float y = 60 - sin( n * i * j - fase) * 10 ;
float x = i * 55 / 700 ;
tft.drawCircle(x, y, 1, ST7735_WHITE);
}
Serial.println(millis()); // shows slow time not according
}
hello, the for loop makes it graph the wave if I remove it, it won't, I have investigated that there is a way to create it using a lookup table but I don't know how to implement it
Use a baudrate of minimum 115200.
Depending on your microcontrollers clock beeing maybe 48 MHz or even more you can go up to 1 Mbaud or 2 MBaud
void loop() is looping
and non-blocking timing means that the only loop that is looping is void loop() itself
You can write code that does the same thing as a for-loop only with if-conditions.
function loop() itself is looping and will make your variable count up the same way as the for-loop does
Again depending on your microcontroller if your µC has enough RAM to hold all the values that you are calculating you could calculate all the values in function setup store the values in an array and then iterate through the array by incrementing the array-inde