Explanation of code

Hello everyone , I am using PLX DAQ V2.11 to transfer data from IDE to Excel. However I am successfull in transfering the data, but I dont know the meaning of the code. Can you please expain me how the code is executed here.
Especiialy the millis() function and why Serial.println(RESETTIMER) is ommited .

unsigned long TIMER;
int led=4;
int sensor=A0;
int threshold=90;
void setup() {

void loop() {
int value=analogRead(sensor); 
TIMER= millis();
  if (value>=threshold)
    digitalWrite(4, HIGH);
  digitalWrite(4, LOW);

Thank you.

TIMER= millis();

You are not using TIMER.


Hello LarryD thanks for the suggestion. But the code I am using is perfectly fine. All I want is the explanation of the code. I am not a coder .

The point is TIMER doesn’t appear to be used , comment it out and see what happens

[quote="modhu_54, post:3, topic:870297"]
But the code I am using is perfectly fine.[/quote]
Your code might compile but it is not perfectly fine.

This is not a useful request to ask. There are books full of information that could be given about the code. If you have no idea where to start I recommend to look for a introduction to C/C++ programming. This is available for reading and video.
If you are interested in the specific functions of the example use Google to search into the Arduino Reference. e.g. Arduino analogRead


Or you can start here:


If you do not understand something, come back and ask specific questions. These tend to get better answers.

I do not know anyone who calls themselves a coder. Maybe you can tell us what you want to do with your knowledge about software. That will help us point you in the right direction.

Here are a few points that could be criticized about your code:

  • good software tries to keep naming conventions to make code easier to read and detect potential errors Arduino recommends to use camelCase for all variables and functions. e.g. timer not TIMER, ALL_UPPERCASE_WITH_UNDERSCORE is used for constants
  • you create a variable for led but it is not used
  • your sketch prints CLEARDATA without any reason why that would be the case, is there any data that is cleared
  • you write millis into the TIMER variable but you do not use it
  • a short description of the sketch at the beginning could be useful

This should explain a lot.

That rather implies you need to learn coding. There are many online resources for this. To start with though you can search the various keywords and function names used in the code to get a better understanding of what they do.

I note the code is incorrectly indented which won't help - auto-indenting the code will reveal the actual structure.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.