Skip to main content
added 2 characters in body
Source Link
Michel Keijzers
  • 13k
  • 7
  • 42
  • 59

If I understand you well, it's very easy.

Assuming the 4 outputs of the switch will be connected to 4 GPIO's you just can check for the state of each GPIO and act on it

// AdjustPin thesenumbers valueswhere switch 1 to the4 correctare pinattached numbersto.
#define PIN_SWITCH_1 1 8
#define PIN_SWITCH_2 2 9
#define PIN_SWITCH_3 310
#define PIN_SWITCH_4 411

unsigned long timer_value = 1000; // No switch selected

void setup()
{
     // Set switch pins to input mode.
     pinMode(PIN_SWITCH_1, INPUT); 
     pinMode(PIN_SWITCH_2, INPUT); 
     pinMode(PIN_SWITCH_3, INPUT); 
     pinMode(PIN_SWITCH_4, INPUT); 

     // Check switches
     if (digitalRead(PIN_SWITCH_1) == HIGH)
     {
         timer_value = 30000;
     }
     else if (digitalRead(PIN_SWITCH_2) == HIGH)
     {
         timer_value = 60000;
     }
     else if (digitalRead(PIN_SWITCH_3) == HIGH)
     {
     .....    timer_value = 90000;
     }
     else if (digitalRead(PIN_SWITCH_4) == HIGH)
     {
         timer_value = 120000;
     }
     else
     {
         // Keep default value
     }
 }

 void loop()
 {
     // Here you can use timer_value to check for the end of the game.
 }

If I understand you well, it's very easy.

Assuming the 4 outputs of the switch will be connected to 4 GPIO's you just can check for the state of each GPIO and act on it

// Adjust these values to the correct pin numbers
#define PIN_SWITCH_1 1
#define PIN_SWITCH_2 2
#define PIN_SWITCH_3 3
#define PIN_SWITCH_4 4

unsigned long timer_value = 1000; // No switch selected

void setup()
{
     // Set switch pins to input
     pinMode(PIN_SWITCH_1, INPUT); 
     pinMode(PIN_SWITCH_2, INPUT); 
     pinMode(PIN_SWITCH_3, INPUT); 
     pinMode(PIN_SWITCH_4, INPUT); 

     // Check switches
     if (digitalRead(PIN_SWITCH_1) == HIGH)
     {
         timer_value = 30000;
     }
     else if (digitalRead(PIN_SWITCH_2) == HIGH)
     {
         timer_value = 60000;
     }

     .....
 }

 void loop()
 {
     // Here you can use timer_value 
 }

If I understand you well, it's very easy.

Assuming the 4 outputs of the switch will be connected to 4 GPIO's you just can check for the state of each GPIO and act on it

// Pin numbers where switch 1 to 4 are attached to.
#define PIN_SWITCH_1  8
#define PIN_SWITCH_2  9
#define PIN_SWITCH_3 10
#define PIN_SWITCH_4 11

unsigned long timer_value = 1000; // No switch selected

void setup()
{
     // Set switch pins to input mode.
     pinMode(PIN_SWITCH_1, INPUT); 
     pinMode(PIN_SWITCH_2, INPUT); 
     pinMode(PIN_SWITCH_3, INPUT); 
     pinMode(PIN_SWITCH_4, INPUT); 

     // Check switches
     if (digitalRead(PIN_SWITCH_1) == HIGH)
     {
         timer_value = 30000;
     }
     else if (digitalRead(PIN_SWITCH_2) == HIGH)
     {
         timer_value = 60000;
     }
     else if (digitalRead(PIN_SWITCH_3) == HIGH)
     {
         timer_value = 90000;
     }
     else if (digitalRead(PIN_SWITCH_4) == HIGH)
     {
         timer_value = 120000;
     }
     else
     {
         // Keep default value
     }
 }

 void loop()
 {
     // Here you can use timer_value to check for the end of the game.
 }
added 16 characters in body
Source Link
Juraj
  • 18.3k
  • 4
  • 32
  • 50

If I understand you well, it's very easy.

Assuming the 4 outputs of the switch will be connected to 4 GPIO's you just can check for the state of each GPIO and act on it

// Adjust these values to the correct pin numbers
#define PIN_SWITCH_1 1
#define PIN_SWITCH_2 2
#define PIN_SWITCH_3 3
#define PIN_SWITCH_4 4

unsigned long timer_value = 1000; // No switch selected

void setup()
{
     // Set switch pins to input
     pinMode(SWITCH_1PIN_SWITCH_1, INPUT); 
     pinMode(SWITCH_1PIN_SWITCH_2, INPUT); 
     pinMode(SWITCH_1PIN_SWITCH_3, INPUT); 
     pinMode(SWITCH_1PIN_SWITCH_4, INPUT); 

     // Check switches
     if (digitalRead(PIN_SWITCH_1) == HIGH)
     {
         timer_value = 30000;
     }
     else if (digitalRead(PIN_SWITCH_2) == HIGH)
     {
         timer_value = 60000;
     }

     .....
 }

 void loop()
 {
     // Here you can use timer_value 
 }

If I understand you well, it's very easy.

Assuming the 4 outputs of the switch will be connected to 4 GPIO's you just can check for the state of each GPIO and act on it

// Adjust these values to the correct pin numbers
#define PIN_SWITCH_1 1
#define PIN_SWITCH_2 2
#define PIN_SWITCH_3 3
#define PIN_SWITCH_4 4

unsigned long timer_value = 1000; // No switch selected

void setup()
{
     // Set switch pins to input
     pinMode(SWITCH_1, INPUT); 
     pinMode(SWITCH_1, INPUT); 
     pinMode(SWITCH_1, INPUT); 
     pinMode(SWITCH_1, INPUT); 

     // Check switches
     if (digitalRead(PIN_SWITCH_1) == HIGH)
     {
         timer_value = 30000;
     }
     else if (digitalRead(PIN_SWITCH_2) == HIGH)
     {
         timer_value = 60000;
     }

     .....
 }

 void loop()
 {
     // Here you can use timer_value 
 }

If I understand you well, it's very easy.

Assuming the 4 outputs of the switch will be connected to 4 GPIO's you just can check for the state of each GPIO and act on it

// Adjust these values to the correct pin numbers
#define PIN_SWITCH_1 1
#define PIN_SWITCH_2 2
#define PIN_SWITCH_3 3
#define PIN_SWITCH_4 4

unsigned long timer_value = 1000; // No switch selected

void setup()
{
     // Set switch pins to input
     pinMode(PIN_SWITCH_1, INPUT); 
     pinMode(PIN_SWITCH_2, INPUT); 
     pinMode(PIN_SWITCH_3, INPUT); 
     pinMode(PIN_SWITCH_4, INPUT); 

     // Check switches
     if (digitalRead(PIN_SWITCH_1) == HIGH)
     {
         timer_value = 30000;
     }
     else if (digitalRead(PIN_SWITCH_2) == HIGH)
     {
         timer_value = 60000;
     }

     .....
 }

 void loop()
 {
     // Here you can use timer_value 
 }
Source Link
Michel Keijzers
  • 13k
  • 7
  • 42
  • 59

If I understand you well, it's very easy.

Assuming the 4 outputs of the switch will be connected to 4 GPIO's you just can check for the state of each GPIO and act on it

// Adjust these values to the correct pin numbers
#define PIN_SWITCH_1 1
#define PIN_SWITCH_2 2
#define PIN_SWITCH_3 3
#define PIN_SWITCH_4 4

unsigned long timer_value = 1000; // No switch selected

void setup()
{
     // Set switch pins to input
     pinMode(SWITCH_1, INPUT); 
     pinMode(SWITCH_1, INPUT); 
     pinMode(SWITCH_1, INPUT); 
     pinMode(SWITCH_1, INPUT); 

     // Check switches
     if (digitalRead(PIN_SWITCH_1) == HIGH)
     {
         timer_value = 30000;
     }
     else if (digitalRead(PIN_SWITCH_2) == HIGH)
     {
         timer_value = 60000;
     }

     .....
 }

 void loop()
 {
     // Here you can use timer_value 
 }