class SoftTmr {
public:
void setTimer(uint32_t t) {
m_timer = t;
}
uint32_t getTimer() const { return m_timer; }
bool isRun() const { return m_isRun ;}
bool isStop() const { return !m_isRun; }
void start() {
if (!m_isRun) {
m_time = millis();
m_isRun = true;
}
}
void stop() {
m_isRun = false;
m_isElapsed = false;
}
void restart() {
m_isRun = false;
start();
}
bool isElapsed() {
if (!m_isRun || m_isElapsed)
return false;
m_isElapsed = millis() - m_time >= m_timer;
return m_isRun & m_isElapsed;
}
private:
bool m_isRun;
bool m_isElapsed;
uint32_t m_time;
uint32_t m_timer;
};
SoftTmr timer0;
const byte KONST = 10;
// using array_t = int[]; non ffunge senza specificare la dimensione
/*void usingArray(const array_t &a) {
}*/
// Restituisce il numero di elementi di un array
// Es:
// int myArray[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
// Serial.print("size(myArray): ");
// Serial.println(size(myArray));
// stampa: size(myArray): 10
// La dimensione in byte vale 10 x sizeof(int)
template <class T, size_t N>
constexpr size_t size(const T (&array)[N]) {
return N;
}
template <class T, size_t N>
void myFunc(const T (&array)[N]) {
for (byte idx = 0; idx < N; idx++) {
Serial.println(array[idx]);
}
Serial.print("size:\t");
Serial.println(N);
Serial.println(sizeof(array) / sizeof array[0]);
Serial.println((uint16_t)&array, HEX);
}
template <class T>
void myFuncSimple(const T (&array)) {
size_t N = sizeof(array) / sizeof array[0];
for (byte idx = 0; idx < N; idx++) {
Serial.println(array[idx]);
}
}
void vla() {
Serial.println("vla");
uint16_t a1Raw = analogRead(A1);
Serial.println(a1Raw);
int vettore[a1Raw];
Serial.println((uint16_t)&vettore, HEX);
Serial.println(sizeof vettore);
Serial.println(sizeof vettore / sizeof vettore[0]);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
//KONST = 10; // il compilatore termina con errore
//Serial.println(KONST);
//Serial.println(digitalPinToInterrupt(3));
//Serial.println(INT1);
int myArray[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
Serial.println((uint16_t)&myArray, HEX);
Serial.print("size(myArray): ");
Serial.println(size(myArray));
//myFunc(myArray);
//myFuncSimple(myArray);
//myF(myArray);
vla();
timer0.setTimer(500);
timer0.start();
}
bool oneShot = false;
int *myPtr = 0x8E8;
void loop() {
if (timer0.isElapsed()) {
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
Serial.println("timer0 is elapsed");
//timer0.restart();
/*if (timer0.getTimer() > 100) {
timer0.setTimer(timer0.getTimer() - 10);
timer0.restart();
} else {
timer0.stop();
Serial.println("timer0 is stopped");
}*/
}
/*if (!oneShot) {
//vla();
for (byte i = 0; i < 11; i++) {
Serial.println((int)*myPtr++, HEX);
}
Serial.println((int)myPtr, HEX);
oneShot = true;
}*/
// put your main code here, to run repeatedly:
}