Blink without delay

Status
Not open for further replies.

Dellyjoe

Active member
Good Afternoon

looked at the blink without delay. I feel I understand the function but it isn't working for me I don't understand why

Code:
#include <Arduino.h>
#include <potentiometer.h>
#include <OLED.h>
#include <rtc.h>
//#include <LED.h>
#include <wire.h>
//*****************************************Declare*****************************//
// Function prototyping
const int timer12 = 13; // setting timer to ditigal pin 13 for LED example
void setup();
int replaystate = LOW;            // a state for the relay
unsigned long previousMillis = 0; // stores last updated vaule of relay
const long interval12 = 2000;
void timer();
//*****************************************Declare*****************************//
//******************************************Main******************************//

int main()
{

  Potentiometer PotentiometerO;
  OLED OLEDO;
  OLEDO.intdisplay();
  displaytime();
  //ledblink();
  timer(); // Will this allow while loop to run or will it not before the void loop will not end?

  while (true)
  {

    PotentiometerO.getpot();
    OLEDO.OLEDdraw(PotentiometerO.getpot());
  }
  return (0);
} // end int main
//******************************************Main******************************//
//******************************************Setup*****************************//
void setup()
{
  // set the digital relay pin an output
  pinMode(timer12, OUTPUT); // setting pin 3 to an output pin
} //end setup
//******************************************Setup*****************************//
//*****************************************Functions**************************//
void timer()
{
  //check to see if it is time to turn on the relay
  unsigned long currentMillis = millis();
  if ((currentMillis - previousMillis) >= interval12)
  {
    // save the last time you turned on the relay
    previousMillis = currentMillis;

    // if the relay is off turn it on and vice-versa:
    if (replaystate == LOW)
    {

      replaystate = HIGH;
    }
    else
    {

      replaystate = LOW;
    }
    digitalWrite(timer12, replaystate); // setting the relay state to the realy pinout
  }
} // end timer
  //*****************************************Functions**************************//
 
Your main() function will override and replace the one automatically supplied by Teensyduino. It sets up the hardware - including the timer for millis() amongst other things.
There is no loop function because your main() function didn't call one. And setup() won't be called because your main function didn't call it either.
Best thing to do is get rid of your main function altogether and rewrite your code using the setup() and loop() "paradigm".

Pete
 
Your main() function will override and replace the one automatically supplied by Teensyduino. It sets up the hardware - including the timer for millis() amongst other things.
There is no loop function because your main() function didn't call one. And setup() won't be called because your main function didn't call it either.
Best thing to do is get rid of your main function altogether and rewrite your code using the setup() and loop() "paradigm".

Pete

So yes i'm really new to coding and c++ in general

before I make all of these changes, I though that int main with return (0) is basically just a void loop function.

But after reading your post over and over again I feel that this void loop () for your main program has things in the background that it calls to set everything up.

Thank you so much for asking, if this is right I will work on getting my code fixed to have void main over int main.
 
The code started working when I used the void loop.


Thank you everyone, I hope this will fix my time issue I was having to


Joe
 
Good eye/focus Pete - I didn't even look at the code open …

@Dellyjoe - in the IDE there are Examples for code that show the general use of setup() and loop() - that is the standard Arduino way - where Arduino owns main() to make the startup uniform for the device and user.

That special organization in the sketch .INO makes it different from normal c/C++ code, after that or beyond that it is all done with a standard C++ build system.
 
Good eye/focus Pete - I didn't even look at the code open …

@Dellyjoe - in the IDE there are Examples for code that show the general use of setup() and loop() - that is the standard Arduino way - where Arduino owns main() to make the startup uniform for the device and user.

That special organization in the sketch .INO makes it different from normal c/C++ code, after that or beyond that it is all done with a standard C++ build system.

ok thank you !!

Now I will learn how to only update the display after the pot value has changed !! This stuff is really exciting !
 
Status
Not open for further replies.
Back
Top