Arduino Workshop - Chapter Three - SWITCH CASE Statements

preview_player
Показать описание

In this section, we'll dive into using 'switch' cases to implement comparative lists and outcomes.

Рекомендации по теме
Комментарии
Автор

[In Borat's voice] Very nice, i like! High five!!!

thomasalexander
Автор

I would like to put this out there: when using the switch case functions, a semicolon must be included at the end of the last case line before declaring a break, so that it will recognize the case function and break.

harrisonhill
Автор

This actually really helped. Sure explained it better than my college professor

sasukecruz
Автор

Hello, thank you for the video. When switch case is triggered, how does it know which switch case is which? I did not see you defining that case 0 is value [0:51] (255:5=51) or case 1 is 51:102.

kristapsberzins
Автор

Please i need yur help! Can a switch case run on arduino setup to switch 2pwm code on one pin please please

paulpixzy
Автор

i have a question. If i want a more accurate potentiometer value then can i turn it into a float when dividing the original value by 4

bitcloud
Автор

can we make a code like this
switch(situation && led1){
case 1 && HIGH:
do something
break;
}

andremuslim
Автор

Been trying to use "if' to switch between "Stepper Sp Control" loop and "Motor Knob" loop. Compiles fine, but still doesn't work. I'll try implementing it with "switch / case" and see if it helps. Any suggestions?

andrewferg
Автор

really good explanation. sometimes we use if (if...)I mean if inside if, can we use it in switch case? switch case(somevalue1)
case (switch case(somevalue2):??. can you help. will be grateful.

naboulsikhalid
Автор

little disappointed a tutorial workshop doesn't have any replies to comments...

DIVERGEsound
Автор

Thanks for this video! I just happened to stumble across it as I was trying to come up with the best way to do a project, and it was the perfect timing. I got the sketch completed in record time because of this tutorial.

robinfeathers
Автор

HI
can you help and suggest me how to add 2 second delay in the any of CASE .

Quantum_innovations
Автор

Hi, well it's a bit hard when setting a User interface LCD menu and sub menu
its complicating for even a simple RTC ds3231 TIME and Date setup with a rotary encoder
i hope you make a Tuto covering this bit example
thanks

akroutsamo
Автор

I am getting Arduino: 1.8.5 (Windows Store 1.8.10.0) (Windows 10), Board: "Arduino/Genuino Uno"

In file included from

error: expected unqualified-id before numeric constant

#define DFR_LCD_KEYPAD_KEY_SELECT 4

^

note: in expansion of macro 'DFR_LCD_KEYPAD_KEY_SELECT'

#define KEY_SELECT DFR_LCD_KEYPAD_KEY_SELECT

^

note: in expansion of macro 'KEY_SELECT'

int KEY_SELECT;

^

In function 'void loop()':

dice_for_catan:37: error: case label '1' not within a switch statement

case 1:

^

dice_for_catan:39: error: break statement not within loop or switch

break;

^

dice_for_catan:41: error: case label '0' not within a switch statement

case 0:

^

dice_for_catan:42: error: 'nothing' was not declared in this scope

do nothing

^

dice_for_catan:43: error: expected 'while' before '}' token

}

^

dice_for_catan:43: error: expected '(' before '}' token

dice_for_catan:43: error: expected primary-expression before '}' token

dice_for_catan:43: error: expected ')' before '}' token

dice_for_catan:43: error: expected ';' before '}' token

At global scope:

dice_for_catan:46: error: expected constructor, destructor, or type conversion before '(' token

randomSeed(analogRead(0));

^

dice_for_catan:48: error: 'diceOne' does not name a type

diceOne = random(1, 7);

^

dice_for_catan:49: error: 'diceTwo' does not name a type

diceTwo = random(1, 7);

^

dice_for_catan:52: error: expected constructor, destructor, or type conversion before ';' token

buildUp();

^

dice_for_catan:53: error: 'lcd' does not name a type

lcd.clear();

^

dice_for_catan:54: error: 'lcd' does not name a type

lcd.setCursor(7, 0);

^

dice_for_catan:55: error: 'lcd' does not name a type

lcd.print(diceOne);

^

dice_for_catan:56: error: 'lcd' does not name a type

lcd.setCursor(7, 1);

^

dice_for_catan:57: error: 'lcd' does not name a type

lcd.print(diceTwo);

^

dice_for_catan:59: error: expected unqualified-id before 'if'

if (diceOne + diceTwo == 7) {

^

dice_for_catan:67: error: expected unqualified-id before 'if'

if (diceOne + diceTwo == 5, 4, 3, 2, 6 ){

^

dice_for_catan:72: error: expected declaration before '}' token

}

^

exit status 1
case label '1' not within a switch statement

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
can someone help me with this code?
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
#include <DFR_LCD_Keypad.h>
#include <AnalogDebounce.h>
int localKey = 1;
int count = 0;
long diceOne;
long diceTwo;
int countDelay = 220;
int setColumn = 0;
int SAMPLE_WAIT;
int KEY_SELECT;

void setup() {
lcd.begin(2, 16);
lcd.setCursor(8, 0);
lcd.print("Roll the dice!");

}


void buildUp() {
lcd.clear();
for (count = 0; count <= 16; count++) {
lcd.setCursor(setColumn, 0);
lcd.print(random(1, 7));
lcd.setCursor(setColumn, 1);
lcd.print(random(1, 7));
delay(countDelay);
countDelay -= 13;
setColumn += 1;
}
}

void loop() {
switch (KEY_SELECT);
case 1:
lcd.print("rolling dice");
break;

case 0:
do nothing
}


randomSeed(analogRead(0));

diceOne = random(1, 7);
diceTwo = random(1, 7);


buildUp();
lcd.clear();
lcd.setCursor(7, 0);
lcd.print(diceOne);
lcd.setCursor(7, 1);
lcd.print(diceTwo);

if (diceOne + diceTwo == 7) {
lcd.clear();
lcd.setCursor(7, 0);
lcd.print("7");
lcd.setCursor(3, 1);
lcd.print("The pirate");


if (diceOne + diceTwo == 5, 4, 3, 2, 6 ){
lcd.clear();
lcd.setCursor(7, 0);
lcd.print("5, 4, 3, 2, 6");
}
}
}
BTW I'm trying to make a digital dice to play catan dice

taranagnew
Автор

Have you done a video on using "namespace" ?

robertsquires
Автор

is it also possible to make a case for multiple cases like case 1 or 2:

skatefreak
Автор

And the motor doesn't work... It prints to serial I'm here in this case and the motor doesn't start. How do you keep the motor running without a delay?

amelliamendel
Автор

I wanted your help on a project like SWITCH..case 0: (volts = xxx .. loop) push button changes to case 1: temperature = xxx ° c ... loop) on a lcd 20x4 or 16x2

dragonsocram
Автор

how to do that with a PIR Sensor returning only HIGH and LOW?
there is no MEDIUM there, I just want to turn on the led if high, off if "medium" and on if low'

empaguia
Автор

Excellent! ... but how do I do when the "case" is a string? I have a list of strings to execute a different function for each string...

dajhonjosioechenique
join shbcf.ru