Programming in (and wiring tbh) buttons to control functions

I need help writing code (and probably laying out the bread board and such tbh)for a project I’m working on, and I’m pretty new at this. So far I have a patchwork of codes I’ve used for beginner projects. I have the lights going but no way to manually control them. What I want to have happen is:
I want the program to start with everything off, then I want a button press to make 2 separate LEDs on separate pins ( 10 and 11) to both run for 1 minute.
1 LED (pin 10 will run solid but with a higher resister (1k) to make it dim. The other LED will strobe at a delay of 4 for 55 seconds and a then switch to a delay of 8 for the last 5 seconds. After that I want it to shut off until I press it again.
I also want a second button that will turn both on solid and turn off when I press that button again.

I’m testing it all on my UNO but it will all be going on a pro mini 3.3v (and running off a Lithium ion battery through the VIN)

// Light_Up_Armor
int strobeledPin = 11; //LED that strobes
int dimledPin = 10; //LED that is solid dim
float sinVal;
int ledVal;
int button = 3; //button that starts both lights and runs for 1 minute
void setup() {
pinMode(strobeledPin, OUTPUT);
pinMode(dimledPin, OUTPUT);
pinMode (button, INPUT):
}
void loop() {
int state = digitalRead(button);
/* check if button is pressed
 */for (int x=0; x<180; x++) {
// convert degrees to radians
// then obtain sin value
sinVal = (sin(x*(3.1412/180)));
ledVal = int(sinVal*255);
analogWrite(strobeledPin, ledVal);
delay(4); //speed of strobe
digitalWrite(dimledPin, HIGH); // LED constant dim 
}
}

Try This :slight_smile:

/*Sequence:
  I want the program to start with everything off,
  then I want a button press to make 2 separate LEDs on separate pins ( 10 and 11) to both run for 1 minute.
  1 LED (pin 10 will run solid but with a higher resister (1k) to make it dim.
  The other LED will strobe at a delay of 4 for 55 seconds
  and a then switch to a delay of 8 for the last 5 seconds.
  After that I want it to shut off until I press it again.

  I also want a second button that will turn both on solid and turn off when I press that button again.

  I'm testing it all on my UNO but it will all be going on a pro mini 3.3v (and running off a Lithium ion battery through the VIN)
*/
// Light_Up_Armor
int strobeledPin = 11; //LED that strobes
int dimledPin = 10; //LED that is solid dim
float sinVal;
int ledVal;
int button = 3; //button that starts both lights and runs for 1 minute
void setup() {
  pinMode(strobeledPin, OUTPUT);
  pinMode(dimledPin, OUTPUT);
  pinMode (button, INPUT);
}
void loop() {
  static int Active = 0; // Using the keyword "static" keeps the value between loops instead of starting over at zero each time
  static int SecondsElapsed;
  unsigned long x;
  static unsigned long SecondTimer;
  if ( (unsigned long)(millis() - SecondTimer) >= (1000)) { //<< the famous blink without delay timer everyone will tell you about
    SecondTimer = millis();
    SecondsElapsed += Active; // once the button gets latched
  }
  Active = max(Active, (digitalRead(button) == HIGH) ? 1 : 0); // Latches state to 1 when button is pressed
  static unsigned long strobeTimer;
  int delayTime;
  delayTime = (SecondsElapsed <= 55) ? 4 : 8;
  if ( (unsigned long)(millis() - strobeTimer) >= (delayTime)) { // 4 Second or 8 Second
    strobeTimer = millis();
    x++;
    sinVal = (sin(x % 180 * (3.1412 / 180)));
    ledVal = int(sinVal * 255);
    analogWrite(strobeledPin, ledVal);
  }
  digitalWrite(dimledPin, Active ? HIGH : LOW); // LED constant dim
  if (SecondsElapsed >= 60) {
    SecondsElapsed = 0;
    Active = 0;
  }
}

Z

http://www.gammon.com.au/switches

http://www.gammon.com.au/blink

  delayTime = (SecondsElapsed <= 55) ? 4 : 8;
  if ( (unsigned long)(millis() - strobeTimer) >= (delayTime)) { // 4 Second or 8 Second

4 seconds would be 4000 milliseconds

Human eyes can’t see a 4 or 8 milli strobe as anything but dimmer light.

GoForSmoke:
Gammon Forum : Electronics : Microprocessors : Switches tutorial

Gammon Forum : Electronics : Microprocessors : How to do multiple things at once ... like cook bacon and eggs

  delayTime = (SecondsElapsed <= 55) ? 4 : 8;

if ( (unsigned long)(millis() - strobeTimer) >= (delayTime)) { // 4 Second or 8 Second




4 seconds would be 4000 milliseconds

Human eyes can't see a 4 or 8 milli strobe as anything but dimmer light.

your right it shouldn’t read seconds
in his code:

delay(4); //speed of strobe

and its the rate of change * 180
per his code for the analogwrite

sinVal = (sin(x*(3.1412/180)));
ledVal = int(sinVal*255);
analogWrite(strobeledPin, ledVal);

Then it's only the comment that needs "fixing".

sinVal = (sin(x*(3.1412/180)));
ledVal = int(sinVal*255);

One really smart move would be to table the results of sine x 255 for 180 values of x in PROGMEM and look up the one needed. It gets rid of floats and float operations, the lookup can take less than a microsecond.