I don't know why this R&D sketch I made from example code causes the Web Editor to crash but it does. The sketch has two files. This is the main file:
#include <SPI.h>
#include <MPU6050.h>
#include <Wire.h>
#include <U8g2lib.h>
#include "lib_test.c"
MPU6050 mpu;
int16_t ax, ay, az, gx, gy, gz;
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0);
const int buttonPin = 4;
int counter = 0;
int buttonState;
int lastButtonState = LOW;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
void setup() {
pinMode(buttonPin, INPUT);
u8g2.begin();
Serial.begin(9600);
mpu.initialize();
if (!mpu.testConnection()) {
while (1);
}
}
void loop() {
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == LOW && counter >= 0 && counter < 10) {
counter++;
}
else if (buttonState == LOW && counter >= 2) {
counter = 0;
}
}
}
lastButtonState = reading;
switch (counter) {
case 1:
printInt(10, 10, counter);
break;
case 2:
printInt(10, 10, ax);
break;
default:
printInt(10, 10, 0);
break;
}
}
This is the second file, which contains the printInt() function:
#include <U8g2lib.h>
void printInt(int _cursorX, int _cursorY, int _varToPass) {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_t0_11_tf);
u8g2.setCursor(_cursorX, _cursorY);
u8g2.print(_varToPass);
u8g2.sendBuffer();
}
The crash happened upon creation of the function file and seems to be caused by the #include up top. Except that it doesn't work if I remove it.
Is this a problem with me or the Web IDE?
EDIT - The name of the second file is "lib_test.c".