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.
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.
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.
basically its the division part, pot value is an int, which means it can be 0,1,2,3... but not 2.43, 3.98 or most importantly 13.69, because of this when you divide 1023 by 255, the max that it can give is 5 different values because 1023/255 is 4.011 = 4 since potvalue is an integer so it rounds to nearest int i think, then its 3 when potentiometer is around 768, 2 when potentiometer is around 513, 1 when potentiometer is around 258, and 0 when potentiometer is around 3, since it divides it and cant take deciamals, it rounds them and because the maximum is 4 since 1023 is the maximum potentiometer can go up to and 1023/255 is 4, then you have 0,1,2,3,4 values and you do cases based on each different number. hope this helps
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.
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
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
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'
I have a question! I tried putting a “delay” in one of my cases. “Case 3: LED1 HIGH delay LED2 HIGH” and it kept looping that one case. The LED stopped reacting to the button I was using. So once I got to that case it kept going LED1 high LED2 high LED1 high LED2 high…. And so on. Can you help me?
Hi! We can best handle support over on our forums where its easier to share code and photos of your setup. Head over to forum.core-electronics.com.au/, or leave a comment at the bottom of the workshop page. We're full-time makers and here to help!
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?
im making a rc car using a little joystick that ranges from 0 to 240, in my previous code i kept using if(value > 10) {goslow;} else{} if(value >50) {gofast;} else{} when using the if statements i could use ranges of numbers using the lesser than or greater than symbols but with switch... case it doset let me use < or > please help
I am getting Arduino: 1.8.5 (Windows Store 1.8.10.0) (Windows 10), Board: "Arduino/Genuino Uno" In file included from C:\Users\taran\Documents\Arduino\dice_for_catan\dice_for_catan.ino:3:0: C:\Users\taran\Documents\Arduino\libraries\DFR_LCD_Keypad-master/DFR_LCD_Keypad.h:35:35: error: expected unqualified-id before numeric constant #define DFR_LCD_KEYPAD_KEY_SELECT 4 ^ C:\Users\taran\Documents\Arduino\libraries\DFR_LCD_Keypad-master/DFR_LCD_Keypad.h:55:20: note: in expansion of macro 'DFR_LCD_KEYPAD_KEY_SELECT' #define KEY_SELECT DFR_LCD_KEYPAD_KEY_SELECT ^ C:\Users\taran\Documents\Arduino\dice_for_catan\dice_for_catan.ino:12:5: note: in expansion of macro 'KEY_SELECT' int KEY_SELECT; ^ C:\Users\taran\Documents\Arduino\dice_for_catan\dice_for_catan.ino: 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 C:\Users\taran\Documents\Arduino\dice_for_catan\dice_for_catan.ino: 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 lcd(8, 9, 4, 5, 6, 7); #include #include 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
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?
@@amelliamendel2227 using a delay will stop all processing. use millus() instead e.g. set a var to millus() compare current millus() to var to get elapsed time, then do something when desired time elapsed time occurs e.g. if millus() - var >= 5000 (5 seconds)
@@amelliamendel2227 there's 3 timers/counter. One 16 bit( arduino's millis function uses this one) and two 8 bit that you can use in many different modes. You can get a smooth acceleration etc with PWM mode or just use CTC mode for your stepper whatever solution you seek for your motor. But in this case you need to open datasheet and set all this stuff on your own or I guess there's Arduino IDE functions that can make your life easier.
use binary to hex; no inputs are high = 0000 = 0, your fourth input is high? 0001 = 1, your first and fourth inputs are high? 1001 = 9, your first, third and fouth inputs are high? 1011 = B, your first, second and fourth inputs are high? 1101 = D, all four inputs are high? 1111 = F
hello Sir , i want to develop a program for relay which can turn on the relay for 1 sec and turn off the relay for 4 sec apart from that i want to use a switch that can reset the relay whenever switch is high. please advise the program
Why do you have to divide by 255, it just rounds to 4 and isnt equal. I get that there are 4 states then but it seems kinda arbitrary. Or is it stemming from byte logic /binary?
U know how it says: int PotValue = analogRead... The integer part means that the value stored will be whole and not decimal. Decimal values are floats.
You don't have to divide but it's just a simple example to show how it works. Dividing analog value by 255 gives you 5 possible numbers which are 0, 1, 2, 3 and 4. Again it's just a simple example to show how the "switch case works". You can create your own function that returns a value and switch to it. For example enum temperature = { Hot, Warm, Cool}; int Pot_value = analogeRead(A0); int get_value (void){ If (Pot_value >=1000 && Pot_value=600 && Pot_value=0 && Pot_value
We are endeavoring to respond more frequently to comments on youTube. Our support team is focused on our forum, where we support our makers : forum.core-electronics.com.au/
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.
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.
This actually really helped. Sure explained it better than my college professor
Thank you - that's great to hear
[In Borat's voice] Very nice, i like! High five!!!
Thank you very much I always love your lessons.
Great job!!
Have you done a video on using "namespace" ?
Very well explained. Thx!
You are the best bro
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.
basically its the division part, pot value is an int, which means it can be 0,1,2,3... but not 2.43, 3.98 or most importantly 13.69, because of this when you divide 1023 by 255, the max that it can give is 5 different values because 1023/255 is 4.011 = 4 since potvalue is an integer so it rounds to nearest int i think, then its 3 when potentiometer is around 768, 2 when potentiometer is around 513, 1 when potentiometer is around 258, and 0 when potentiometer is around 3, since it divides it and cant take deciamals, it rounds them and because the maximum is 4 since 1023 is the maximum potentiometer can go up to and 1023/255 is 4, then you have 0,1,2,3,4 values and you do cases based on each different number. hope this helps
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.
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
Thank you so much bro !!!!!
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
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...
thank you very much
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'
Please i need yur help! Can a switch case run on arduino setup to switch 2pwm code on one pin please please
hey i hv a big problem , my question is if i can switch between two codes using these 2 statements
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
HI
can you help and suggest me how to add 2 second delay in the any of CASE .
Thanks a lot!
Can i use switch case in void setup?
I have a question! I tried putting a “delay” in one of my cases. “Case 3: LED1 HIGH delay LED2 HIGH” and it kept looping that one case. The LED stopped reacting to the button I was using. So once I got to that case it kept going LED1 high LED2 high LED1 high LED2 high…. And so on. Can you help me?
Hi! We can best handle support over on our forums where its easier to share code and photos of your setup. Head over to forum.core-electronics.com.au/, or leave a comment at the bottom of the workshop page. We're full-time makers and here to help!
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?
I need help with switching loops too
im making a rc car using a little joystick that ranges from 0 to 240, in my previous code i kept using if(value > 10) {goslow;} else{} if(value >50) {gofast;} else{}
when using the if statements i could use ranges of numbers using the lesser than or greater than symbols but with switch... case it doset let me use < or > please help
Create a function and switch to it. It's been a long time but if you still need help just let me know lol
great job
Can anyone tell why is there a break in default case in this lesson, because in java this is not needed .?
can we make a code like this
switch(situation && led1){
case 1 && HIGH:
do something
break;
}
I have a question when does it make any diffrence when you use the IF statement and the switch case
10/10
I am getting Arduino: 1.8.5 (Windows Store 1.8.10.0) (Windows 10), Board: "Arduino/Genuino Uno"
In file included from C:\Users\taran\Documents\Arduino\dice_for_catan\dice_for_catan.ino:3:0:
C:\Users\taran\Documents\Arduino\libraries\DFR_LCD_Keypad-master/DFR_LCD_Keypad.h:35:35: error: expected unqualified-id before numeric constant
#define DFR_LCD_KEYPAD_KEY_SELECT 4
^
C:\Users\taran\Documents\Arduino\libraries\DFR_LCD_Keypad-master/DFR_LCD_Keypad.h:55:20: note: in expansion of macro 'DFR_LCD_KEYPAD_KEY_SELECT'
#define KEY_SELECT DFR_LCD_KEYPAD_KEY_SELECT
^
C:\Users\taran\Documents\Arduino\dice_for_catan\dice_for_catan.ino:12:5: note: in expansion of macro 'KEY_SELECT'
int KEY_SELECT;
^
C:\Users\taran\Documents\Arduino\dice_for_catan\dice_for_catan.ino: 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
C:\Users\taran\Documents\Arduino\dice_for_catan\dice_for_catan.ino: 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 lcd(8, 9, 4, 5, 6, 7);
#include
#include
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
is it also possible to make a case for multiple cases like case 1 or 2:
Indeed
does it compares Strings ?
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?
I have sort of the same problem. Did you find a solution?
@@drakkorvladimir4012 no, I have resigned to problem delays in everything
@@amelliamendel2227 using a delay will stop all processing. use millus() instead e.g. set a var to millus() compare current millus() to var to get elapsed time, then do something when desired time elapsed time occurs e.g. if millus() - var >= 5000 (5 seconds)
@@amelliamendel2227 there's 3 timers/counter. One 16 bit( arduino's millis function uses this one) and two 8 bit that you can use in many different modes. You can get a smooth acceleration etc with PWM mode or just use CTC mode for your stepper whatever solution you seek for your motor. But in this case you need to open datasheet and set all this stuff on your own or I guess there's Arduino IDE functions that can make your life easier.
kool one bro
who wrote this kick ass bgm
Hi, I need to compare 4 digital outputs, someone knows how it's done.
If the 4 are in high state of true and continue the program
use binary to hex;
no inputs are high = 0000 = 0,
your fourth input is high? 0001 = 1,
your first and fourth inputs are high? 1001 = 9,
your first, third and fouth inputs are high? 1011 = B,
your first, second and fourth inputs are high? 1101 = D,
all four inputs are high? 1111 = F
if ( digitalReaad(1)==1 && digitalRead (2)==1 && digitalReaad (3)==1 && digitalReaad (4) ==1)
{
// Place your code here
}
hello Sir , i want to develop a program for relay which can turn on the relay for 1 sec and turn off the relay for 4 sec apart from that i want to use a switch that can reset the relay whenever switch is high.
please advise the program
Check out a pin change interrupt
Can you help me to combine two Arduino codings into singe coding...??
#include
What if using ldr?
Why do you have to divide by 255, it just rounds to 4 and isnt equal. I get that there are 4 states then but it seems kinda arbitrary. Or is it stemming from byte logic /binary?
U know how it says:
int PotValue = analogRead...
The integer part means that the value stored will be whole and not decimal. Decimal values are floats.
You don't have to divide but it's just a simple example to show how it works. Dividing analog value by 255 gives you 5 possible numbers which are 0, 1, 2, 3 and 4. Again it's just a simple example to show how the "switch case works". You can create your own function that returns a value and switch to it. For example
enum temperature = { Hot, Warm, Cool};
int Pot_value = analogeRead(A0);
int get_value (void){
If (Pot_value >=1000 && Pot_value=600 && Pot_value=0 && Pot_value
👍
little disappointed a tutorial workshop doesn't have any replies to comments...
We are endeavoring to respond more frequently to comments on youTube. Our support team is focused on our forum, where we support our makers : forum.core-electronics.com.au/
Works, but not accurate
Thank you.
Please ditch the very annoying and completely unnecessary background music.
I had to stick masking tape on my screen to cover your hands
Why??