Control light with switch but not vibration query

Hi everyone!

So I am currently controlling LED lighting through a relay using Arduino and have also connected a vibration pillow to simulate vibration through another relay also controlled by Arduino. The difference is the light needs to be controlled by the switch, (I have got the light to work successfully without the vibration, merely stand alone but introducing the vibration pillow code wise has complicated things), but not the pillow. The code that is below is what I have got but the light is not controlled by the switch and then when I alter the code, the pillow is controlled by the switch - whereas, I want the switch to control the light but not the vibration pillow. Any help would be gratefully appreciated - thanks so much!

#include <Chrono.h>
#include <LightChrono.h>
Chrono myChrono;

int PILLOW = 10;
int LED = 12;
int BUTTON = 4;
long lightsDelay = 1 * 60 * 1000L;
boolean toggle = false;

void setup()
{
Serial.begin(9200);
pinMode(LED, OUTPUT);
pinMode(BUTTON, INPUT);
digitalWrite(LED, HIGH);
myChrono.restart();
myChrono.stop();
}
void lightsOn() {
//Serial.println("on");
digitalWrite(LED, HIGH);

{
Serial.begin(9600);
pinMode(PILLOW, OUTPUT);

digitalWrite(PILLOW, HIGH); // turn the pillow on (HIGH is the voltage level)
delay(8000);

digitalWrite(PILLOW, LOW);
delay(30000);

}

}
void loop()
{
Serial.println(myChrono.elapsed());

if (myChrono.hasPassed(lightsDelay) && toggle == true) {
toggle = false;
myChrono.stop();

lightsOn();
}
{if (digitalRead(BUTTON) == HIGH && toggle == false)
{
//Serial.println("pressed");
toggle = true;
digitalWrite(LED, LOW);
myChrono.restart();
}
}

}

Suggest you ad more serial.write and serial.print to display variables and display where you are in the program and I bet you can figure out the logic problem. SOP, I think.

Paul

You cannot avoid the auto-format feature and expect us to read this stuff.
You cannot throw braces {} around at random and survive.
You should not have both a Serial.begin(9200) and a Serial.begin(9600).
Something called lightsOn should not be turning the pillow on.
lightsOn should not have a call to Serial.begin or to pinMode. Those calls are needed but belong in setup().

Fix those problems, post again, and then I can try to help you.

Thanks for your responses. I am sorry for the mistakes - I am very much a beginner. I am trying to work out where to put the pillow delay function in order for it to not be operated by the switch - any help or advice on how to format would be appreciated

If I understand the code and description correct, you want the pillow to be on for 8 seconds and off for 3 seconds, and this should go on all the time.
You also want the led to be controlled by a switch.

You have some libraries which I am unaware of, but they seems to assist your timing.

One thing I know is you should carefully study this thread, Demonstration code for several things at the same time in Project guidance. It is pure gold and will open your eyes for a better and effective way to programming.

@aliali

The correct answer to vaj4088 post was not to just restate the question. You need to

  1. Read the forum rules and post code properly

  2. Read the response and fix the things it mentions. Especially the format and readability stuff.

  3. Post the updated code with code tags.

When you ignore his advice like that it makes the rest of us not want to help because we don't want to be ignored as well.