Help creating libraries

Hi, I've been trying to create a library to control some sensors and lights with an ARDUINO MEGA and a relay panel, but it is not working, I can compile but it does not run, here is the code:

lights.h:

#ifndef lights_h
#define lights_h
#include <Arduino.h>

void lightSetup();
void frontWhite_on();
void frontWhite_off();
void frontRed_on();
void frontRed_off();
void leftBlinker_on();
void leftBlinker_off();
void rightBlinker_on();
void rightBlinker_off();

#endif

lights.cpp:

#include "lights.h"

void lightSetup() 
{  
// Assign pins to each light
  #define frontWhite 2
  #define frontRed 3
  #define blinkerRight 4
  #define blinkerLeft 5


// set the pin mode
  pinMode (frontWhite, OUTPUT);
  pinMode (frontRed, OUTPUT);
  pinMode (blinkerRight, OUTPUT);
  pinMode (blinkerLeft, OUTPUT);


// set all lights to off
  digitalWrite(frontWhite, LOW);
  digitalWrite(frontRed, LOW);
  digitalWrite(blinkerRight, LOW);
  digitalWrite(blinkerLeft, LOW);
  digitalWrite(positioningBlue, LOW);
}

void frontWhite_on() { // turn on front white lights 
  digitalWrite(frontWhite, HIGH);
}
void frontWhite_off() { // turn off front white lights 
  digitalWrite(frontWhite, LOW);
}
void frontRed_on() { // turn on front red light
  digitalWrite(frontRed, HIGH);
}
void frontRed_off() { // turn off front red light
  digitalWrite(frontRed, LOW);
}
void leftBlinker_on() { // yellow blinker lights cycle (left side)
  digitalWrite(blinkerLeft, HIGH);
  delay(500);
  digitalWrite(blinkerLeft, LOW);
  delay(500);
}
void leftBlinker_off(){
  digitalWrite(blinkerLeft, LOW);
}

void rightBlinker_on() {  // yellow blinker lights cycle (right side)
  digitalWrite(blinkerRight, HIGH);
  delay(500);
  digitalWrite(blinkerRight, LOW);
  delay(500);
}
void rightBlinker_off(){
  digitalWrite(blinkerRight, LOW);
}

lights.ino:

#include "lights.h"

void setup()
{
  void lightSetup();
  void frontWhite_on();
  void frontRed_on();
}

void loop() {

}

any help on what I'm doing wrong will be really appreciated

when you write

this is just a forward declaration of the functions (you are telling the compiler the name of the function, that they don't have any parameters and do not return anything). You are not calling them, so basically your setup() ends up empty.

Try to use

#include "lights.h"

void setup()
{
 lightSetup();
 frontWhite_on();
 frontRed_on();
}

void loop() {

}

THANK YOU SO MUCH!!!!, that mistake was killing me, I really appreciate ypur help, I'm starting in this automation world

Good have fun!

(You might benefit from a C++ introduction tutorial to understand the syntax)

absolutelly right, starting it RN

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