Arduino Workshop - Chapter Three - SWITCH CASE Statements

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 พ.ย. 2024

ความคิดเห็น • 67

  • @robinfeathers650
    @robinfeathers650 4 ปีที่แล้ว +2

    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.

  • @harrisonhill2598
    @harrisonhill2598 3 ปีที่แล้ว +6

    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.

  • @sasukecruz2000
    @sasukecruz2000 6 ปีที่แล้ว +9

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

  • @thomasalexander1851
    @thomasalexander1851 3 ปีที่แล้ว +7

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

  • @punjabilog
    @punjabilog 3 ปีที่แล้ว

    Thank you very much I always love your lessons.

  • @conradstanley1027
    @conradstanley1027 3 ปีที่แล้ว +1

    Great job!!

  • @robertsquires2816
    @robertsquires2816 9 หลายเดือนก่อน

    Have you done a video on using "namespace" ?

  • @InterestingTed
    @InterestingTed 5 ปีที่แล้ว +1

    Very well explained. Thx!

  • @hadizeindeen2422
    @hadizeindeen2422 5 ปีที่แล้ว +1

    You are the best bro

  • @kristapsberzins3867
    @kristapsberzins3867 ปีที่แล้ว +1

    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.

    • @livingwarrobots4119
      @livingwarrobots4119 23 วันที่ผ่านมา +1

      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

  • @naboulsikhalid7763
    @naboulsikhalid7763 5 ปีที่แล้ว +1

    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.

  • @dragonsocram
    @dragonsocram 6 ปีที่แล้ว

    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

  • @thealphamaletube6416
    @thealphamaletube6416 2 ปีที่แล้ว

    Thank you so much bro !!!!!

  • @akroutsamo
    @akroutsamo 5 ปีที่แล้ว +1

    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

  • @dajhonjosioechenique7450
    @dajhonjosioechenique7450 2 ปีที่แล้ว

    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...

  • @bibekmahara1012
    @bibekmahara1012 ปีที่แล้ว

    thank you very much

  • @empaguia
    @empaguia 3 ปีที่แล้ว

    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'

  • @paulpixzy5297
    @paulpixzy5297 ปีที่แล้ว

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

  • @mrpirate6959
    @mrpirate6959 2 ปีที่แล้ว

    hey i hv a big problem , my question is if i can switch between two codes using these 2 statements

  • @bitcloud7732
    @bitcloud7732 4 ปีที่แล้ว +1

    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

  • @Quantum_innovations
    @Quantum_innovations 6 ปีที่แล้ว +1

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

  • @staguyaugustin1825
    @staguyaugustin1825 5 ปีที่แล้ว +1

    Thanks a lot!

  • @paulpixzy5297
    @paulpixzy5297 2 ปีที่แล้ว

    Can i use switch case in void setup?

  • @ineroeder5804
    @ineroeder5804 2 ปีที่แล้ว

    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?

    • @Core-Electronics
      @Core-Electronics  2 ปีที่แล้ว

      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!

  • @andrewferg8737
    @andrewferg8737 4 ปีที่แล้ว +1

    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?

    • @MrBenG3
      @MrBenG3 ปีที่แล้ว

      I need help with switching loops too

  • @rodgerrodger6298
    @rodgerrodger6298 4 ปีที่แล้ว

    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

    • @impulsembedded7147
      @impulsembedded7147 2 ปีที่แล้ว

      Create a function and switch to it. It's been a long time but if you still need help just let me know lol

  • @ryan-dewitt
    @ryan-dewitt 6 ปีที่แล้ว +1

    great job

  • @varunnova5905
    @varunnova5905 4 ปีที่แล้ว

    Can anyone tell why is there a break in default case in this lesson, because in java this is not needed .?

  • @andremuslim9594
    @andremuslim9594 6 ปีที่แล้ว +1

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

  • @janatamer8654
    @janatamer8654 4 ปีที่แล้ว

    I have a question when does it make any diffrence when you use the IF statement and the switch case

  • @hollohollo7228
    @hollohollo7228 4 ปีที่แล้ว +1

    10/10

  • @taranagnew436
    @taranagnew436 6 ปีที่แล้ว

    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

  • @skatefreak381
    @skatefreak381 5 ปีที่แล้ว +2

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

  • @TheMdbProductions
    @TheMdbProductions 4 ปีที่แล้ว

    does it compares Strings ?

  • @amelliamendel2227
    @amelliamendel2227 4 ปีที่แล้ว +1

    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?

    • @drakkorvladimir4012
      @drakkorvladimir4012 4 ปีที่แล้ว

      I have sort of the same problem. Did you find a solution?

    • @amelliamendel2227
      @amelliamendel2227 4 ปีที่แล้ว

      @@drakkorvladimir4012 no, I have resigned to problem delays in everything

    • @rudgeshepherd2204
      @rudgeshepherd2204 3 ปีที่แล้ว

      @@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)

    • @impulsembedded7147
      @impulsembedded7147 2 ปีที่แล้ว

      @@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.

  • @PratapO7O1
    @PratapO7O1 7 ปีที่แล้ว +1

    kool one bro

  • @AndyonSet
    @AndyonSet 6 ปีที่แล้ว +1

    who wrote this kick ass bgm

  • @visual7473
    @visual7473 5 ปีที่แล้ว +1

    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

    • @orthodoxNPC
      @orthodoxNPC 3 ปีที่แล้ว

      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

    • @impulsembedded7147
      @impulsembedded7147 2 ปีที่แล้ว

      if ( digitalReaad(1)==1 && digitalRead (2)==1 && digitalReaad (3)==1 && digitalReaad (4) ==1)
      {
      // Place your code here
      }

  • @prashantvlogs95
    @prashantvlogs95 4 ปีที่แล้ว

    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

  • @siddickraja7884
    @siddickraja7884 4 ปีที่แล้ว

    Can you help me to combine two Arduino codings into singe coding...??

  • @bayugilangramadhan8073
    @bayugilangramadhan8073 4 ปีที่แล้ว

    What if using ldr?

  • @BigHeartBreak93
    @BigHeartBreak93 6 ปีที่แล้ว

    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?

    • @sahan2860
      @sahan2860 6 ปีที่แล้ว

      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.

    • @impulsembedded7147
      @impulsembedded7147 2 ปีที่แล้ว

      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

  • @Hisham_Loh
    @Hisham_Loh 6 ปีที่แล้ว

    👍

  • @DIVERGEsound
    @DIVERGEsound 4 ปีที่แล้ว +2

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

    • @Core-Electronics
      @Core-Electronics  4 ปีที่แล้ว

      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/

  • @jrs0007
    @jrs0007 4 ปีที่แล้ว

    Works, but not accurate

  • @gerrymcerlean8432
    @gerrymcerlean8432 3 ปีที่แล้ว +1

    Thank you.
    Please ditch the very annoying and completely unnecessary background music.

  • @jimbrownza
    @jimbrownza 5 ปีที่แล้ว

    I had to stick masking tape on my screen to cover your hands