Level Up Your Arduino Code: Timer Interrupts

Поделиться
HTML-код
  • Опубликовано: 22 дек 2024

Комментарии •

  • @orignal29
    @orignal29 6 лет назад +128

    I was searching for this exact topic and found this video. When I saw the intro, I thought "oh great another beginner video with cheezy analogies", and almost closed its tab. Lucky me, I didn't. This turned out to be exactly the level I needed (what I consider intermediate). The language was clear and with the right amount of details for me. I liked the fact that the presenter didn't assume I already knew everything while keeping a good technical level. It's obvious a lot of thoughts have been put into the script. Well done!

    • @sebth
      @sebth 5 лет назад +7

      Very well said. I had exactly the same thoughts about the video.

    • @giorsoros1135
      @giorsoros1135 5 лет назад +5

      Exactly

    • @listar1210
      @listar1210 3 года назад

      @Bruce Snode hello bruce, can you help me correcting my code?
      actually i need make 1000Hz frequency sampling for my EMG signal in arduino uno
      but the result cant be sharp at 1000Hz
      here my program
      const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
      const int analogOutPin = 3; // Analog output pin that the LED is attached to
      int sensorValue = 0; // value read from the pot
      int outputValue = 0; // value output to the PWM (analog out)
      void setup() {
      // initialize serial communications at 9600 bps:
      pinMode(3,OUTPUT);
      Serial.begin(9600);
      noInterrupts(); // disable all interrupts
      TCCR1A = 0;
      TCCR1B = 0;
      //TCNT1 = 65484;// preload timer 65536-16MHz/256/1200Hz
      //TCNT1 = 65411;// preload timer 65536-16MHz/256/500Hz
      TCNT1 = 65473;// preload timer 65536-16MHz/256/1000Hz
      //TCNT1 = 65503;// preload timer 65536-16MHz/256/2000Hz
      //TCNT1 = 34286; // preload timer 65536-16MHz/256/2Hz
      TCCR1B |= (1

    • @kennethemmanuel216
      @kennethemmanuel216 3 года назад

      you all prolly dont give a shit but does anybody know a tool to log back into an Instagram account..?
      I was dumb forgot the login password. I appreciate any tricks you can give me

    • @MohamedAshraf-vh3jo
      @MohamedAshraf-vh3jo 3 года назад

      Right you said!

  • @ceneblock
    @ceneblock 2 года назад +15

    I like that you reference the datasheet. That's how people are going to move from online examples to learning and doing things on their own.
    Only thing I would change would be the math part. I was able to follow it after rewatching, but it was a little confusing at first.

  • @joydivisione1420
    @joydivisione1420 4 года назад +9

    These videos are gems! Very insightful for intermediate level which is hard to find in these days. Thank you very much! Keep up the great work!

  • @ymemag9861
    @ymemag9861 6 лет назад +34

    Wow... Very well explained! I did have to watch it 6 times but... it's all there. AWESOME!

  • @johnr3936
    @johnr3936 5 лет назад +10

    I genuinely want to buy your products for releasing this free, incredible information. Keep this trend up, I would love to keep learning about the depths of arduino.

  • @michaelhanagan4121
    @michaelhanagan4121 2 года назад +1

    This is the best tutorial on programming Arduino timers! The programming journey from using "delay()" to bit banging timer registers and using ISRs was perfectly executed. The technical content and simple analogies were very well thought out and presented beautifully by Shawn. Despite this video being based on the Atmel 328P processor I was able to program the timer on an Microchip (Atmel) SAMD21. Well done SparkFun, keep making programming videos like these!

  • @chiefrunningfist
    @chiefrunningfist 2 года назад +2

    The similarity is so uncanny I had to google it. Nope, not related, but definitely the Alton Brown of electronics. IMO, Good Eats is by far the best cooking show, and for the same reasons your videos are so good. Keep up the good work! Great content. Great presentation.

    • @ShawnHymel
      @ShawnHymel 2 года назад +1

      I actually really appreciate this! Alton Brown and Bill Nye are my two biggest sources of inspiration for presenting on camera :)

  • @twanwolthaus
    @twanwolthaus 14 дней назад

    This video is straight to the point with clear explanations and very helpful visuals. This explanation saved my code. Thank you, you brilliant C++ wizzard!

  • @JKTCGMV13
    @JKTCGMV13 4 года назад +1

    Excellent video. I've learned all this years ago in school for another microcontroller, and this was a perfect video to get me up to speed with Atmel.

  • @WhoWantsToKnow81
    @WhoWantsToKnow81 5 лет назад +9

    Excellent tutorial.
    It gets a little more interesting when using an 8-bit timer - then you'll need to count the number of overflows ;)

  • @km5405
    @km5405 6 лет назад +2

    I had a embedded programming course on a ARM-7 platform. really taught me to embrace interrupts!

  • @ColinRichardson
    @ColinRichardson 6 лет назад +19

    These tutorials are amazing.. Please don't stop..
    Do you have a road map of what you plan on teaching for all upcoming "Level Ups" ??

    • @ShawnHymel
      @ShawnHymel 6 лет назад +3

      Thank you! I don't have a road map, as it depends on where I'm needed. If I have time in between other projects, then I'd definitely like to continue them.

    • @ColinRichardson
      @ColinRichardson 6 лет назад +2

      One thing I would like to suggest is something I STILL struggle with, which is deep sleep..
      With the last two tutorials you have done, it has reinvigorated me with wanting to get the Arduino to sleep again and wake up and do something on a pin interrupt (button press) or a timer interrupt.. It would build on what you have been teaching us nicely

    • @ShawnHymel
      @ShawnHymel 6 лет назад +5

      Yes! I was thinking about that one, too. It would build on the interrupts nicely, and I could measure actual power consumption and equate that to battery life. If you're curious, Alex did a really good tutorial showing how to reduce power on the 328p: learn.sparkfun.com/tutorials/reducing-arduino-power-consumption. I don't know if it's exactly what you're looking for, but at least it's a start.

  • @alakazellae-commerce9627
    @alakazellae-commerce9627 3 года назад +1

    I like how Shawn says you can bink with this code
    //pins
    const int led_pin = 13;
    Void set()
    { pin_mode (led_pin; HIGH); [
    void loop() {
    digitalWrite(led_pin, HIGH);
    delay(500);
    digitalWrite(led_pin, LOW);
    delay(500);
    )
    or you can write this much longer code and get the same action. : P i know it for memory and more. It's just funny. SparkFun are the masters. To make a well-thought-out video. Telling how to do something with humor and technology with it not being too watered down.

  • @vivekvenkatsubramaniam437
    @vivekvenkatsubramaniam437 5 лет назад

    Very late, but this series has helped me a lot. Would Sparkfun consider making more such videos? This is such a great resource.

  • @noelwilke8546
    @noelwilke8546 2 года назад

    Your ability to teach is outstanding 👍👍👍👍👍👍

  • @jerryocrow1
    @jerryocrow1 5 лет назад +1

    I hope your funding continues. You are really great.

  • @nvo7024
    @nvo7024 4 года назад +1

    Very good indeed.
    Question: Portability aside, what is the benefit of writing strings of shifted-bit constructs like (15:57)
    TCCR1B |= (1

    • @jslonisch
      @jslonisch 2 года назад

      I think it's just easier to read. If you take a 1 and shift it left 10 or 11 or 12 bits like they are doing here it is obvious exactly what bit in the destination register is being targeted, that is bit 10 or 11 or 12. Sure, for bit 12 they could just XOR it with 4096 decimal or 1000 hex instead, but I certainly don't remember off the top of my head that 4096 equals bit 12. Whereas if you see the CS12 you know without having to work it out that it's bit 12 that will be affected.

    • @Henry-sv3wv
      @Henry-sv3wv 2 года назад

      easier to read is:
      bitWrite(TCCR1B, CS12, 1);
      bitWrite is a macro defined in Arduino.h

  • @shedactivist
    @shedactivist 2 года назад

    This is exactly what I have been looking for. Great presentation and instruction

  • @tanimsk
    @tanimsk 4 года назад

    this video have fixed up my project, I salute you

  • @salmantechnologies282
    @salmantechnologies282 2 года назад

    Kindly make a tutorial on Wire library Your Adventure is so Informative every things perfectly cleared kindly make a tutorial on Wire library and how to access a specific Registers

  • @SurfinScientist
    @SurfinScientist 5 лет назад +1

    Thanks a bunch for this video! I really needed this info for an Arduino application in which timing between pulses is used.

  • @DCFusor
    @DCFusor 6 лет назад +2

    Good show, Shawn. The info at 3:51 used to take a deep dive into the arduino base code or a heck of a lot of googling to find someone else who had. It's really nice to know what interacts with what or what's already in use - engineering is all about trade-offs.
    i see you're now saying "left shift" - it seems fine to allow the beginner to ponder why C used "less than less than" to make numbers bigger...at least it's visually mnemonic. To rag on you just a little further (17:21) - you might take a sentence to say that you're using the various &= and |= (and equals, and or equals) constructs to just affect the bits you want, rather than just jamming the register (since we don't know what the other bits were and don't want to affect them).
    To a noob, that might seem like a hard to understand bunch of back and forthing...so it's good to say why it's actually a good way, and why writing whole registers might cause an issue.
    Now, if we only had the same level of cheat-sheet for the ESP8266 (or ESP32)...which would be a good platform to mention that this is all processor dependent and why we sometimes do it the slower/less efficient way in C (because #ifdefs in header files and macros make the code changes needed for us).

    • @ShawnHymel
      @ShawnHymel 6 лет назад +2

      Yes, thank you for the "left shift" tip! I did mention the single bit flip &= and |= operations in a previous episode, which is why I'm glossing over them here.
      Totally agree with the ESP series. They're fun, cheap little chips, but the documentation is lacking. Perhaps that's what I'll look into next :)

    • @DCFusor
      @DCFusor 6 лет назад

      You're most welcome. The observations stem in part from the fact that I've recently been asked to teach a few beginners myself - "kids ask the darndest questions" - which helps me remember what it was like to be one. I didn't catch all the episodes so I missed that.
      (Hint, I'm getting you to do some of my work for me here... ;~)
      I spent some time looking for info on the ESP-8266, or more specifically the Tensilica (now Cadence) L106 processor, but haven't gotten very far. Cadence only publishes overviews of what appears to be very customizable silicon, the specifics of this seem hard to find - which means that if you guys can find them - very valuable. This is as far as I got: ip.cadence.com/knowledgecenter/resources/know-dip-ds No datasheet like the Atmel so far. I'd hope they aren't so precious with their IP as to make it unusable by keeping the instructions secret! Maybe a deep dive into the source of their libraries? I'd done this for the Uno long ago, to find out things like which timer was already in use for millis() and so on, but wow, this is pretty daunting.

    • @ShawnHymel
      @ShawnHymel 6 лет назад

      I suppose we could always compile different C instructions and take a look at the machine code to decipher what the assembly instructions might be. That sounds like lot of not fun to me, though :P

    • @DCFusor
      @DCFusor 6 лет назад

      No, and it shouldn't be required...but what I can think of so far (other than pinging them to get them to give us a datasheet - where you guys would have more clout than I) might be to look at the defines etc in their code for things like i/o register addresses, usages, and such. After all, most of the arduino C peripheral libraries are pretty well mapped to this thing somehow. I bet it's macros and ifdef kinda stuff, I doubt they re-wrote the world. Time to work up the grep-fu, I guess. The whole world using these things stands to benefit...This isn't as hard to find on the ESP32 as it gets its own obvious directory under Arduino/hardware/... with all kinds of neato header files and info...looking for the 8266...It seems to be hiding elsewhere.
      Ah, a quick search of my linux box shows me these (as a place to begin to start, still, yuck):
      /home/doug/.arduino15/packages/esp8266/hardware/esp8266/2.4.0/cores/esp8266/Arduino.h
      /home/doug/.arduino15/packages/esp8266/hardware/esp8266/2.4.0/tests/device/libraries/BSTest/src/BSArduino.h
      /home/doug/.arduino15/packages/esp8266/hardware/esp8266/2.4.0/tests/host/common/Arduino.h
      Which of course include all manner of other .h files, but I'd bet what we want is in there...and we know it works.

    • @ShawnHymel
      @ShawnHymel 6 лет назад

      Nice sleuthing! I do find it interesting that the ESP32 has a datasheet, but it doesn't cover anything about the instruction set or architecture.

  • @Electrologia
    @Electrologia 2 года назад

    0:22 where is the previous videos? Why Arduino videos not in you Playlist of the channel? Please make the proper playlist!

  • @davewreski6900
    @davewreski6900 6 лет назад +1

    Hello Shawn Hymel,
    I can't tell you how much I enjoy your series! Fantastic to say the least. Keep up the great work. One important question. How can I get the valuable code you teach us so we may try it ourselves? It would be so much help to us so we may understand more of your important information?
    Dave

    • @ShawnHymel
      @ShawnHymel 6 лет назад +1

      Thank you, and good question! I've uploaded the final form of the code as a Gist to GitHub, so you can dissect it at your own pace: gist.github.com/ShawnHymel/d36e527928994150f5fc3cba20dd2161

  • @eruditecoder5215
    @eruditecoder5215 2 года назад

    please provide the datasheet specifically used in this lecture
    there are many available online

  • @martingentieu6850
    @martingentieu6850 Год назад

    I have a question : is there a way to do away with the instruction "delay(500)" ? If we have a timer, do we really need to add a delay ?

  • @6345788
    @6345788 3 года назад

    Great video! I'll be back again to watch it a bunch more times :)

  • @TheSateef
    @TheSateef 6 лет назад

    if you want all your code in an ISR so it runs at a predictable rate, what should you put in loop()? just a delay like in this example or nothing at all? great videos. thanks

  • @mishkin23
    @mishkin23 2 года назад

    I do not know if you could do a routine where two inverted signals are treated, you know, with dead time to control inverters, thanks a lot

  • @soundmartell
    @soundmartell 3 года назад

    Hello. Thank you! It will be very helpful if you make an episode for Timer interrupts for the Atmel SAM3X8E. (Arduino Due)

  • @dioutoroo
    @dioutoroo 2 года назад

    Thank you for your videos! I have a question, how can I implement this for counting RPM from an incremental encoder? Appreciate your help

  • @zeshan2973
    @zeshan2973 6 лет назад +2

    Thank you so much for these great tutorials. Another thing I learned from your tutorials is to read datasheet 😂.

  • @jayeshbhatia6899
    @jayeshbhatia6899 6 лет назад

    Hii
    Tutorials are priceless , Dear i want to read BCD output of 7135 ADC through timer1 in uno . how i will get the values serially coming out from ADC .
    which registers we will use .

  • @abelashenafi6291
    @abelashenafi6291 5 лет назад +1

    could you please provide a link for the datasheet?

  • @jordanmusleh6305
    @jordanmusleh6305 3 года назад

    Thank you for the video but I have a question how make a code for the timer that you had the white box how to make a code like that one..??

  • @BIM0X
    @BIM0X 6 лет назад

    those tutorials are gold !!! so clear and well explained. will you provide one about the ADC and how to scan several potentiometers using Analog Muxer ?

  • @AndreAndrea140
    @AndreAndrea140 4 года назад

    In the viedo is shown CTC option when Compare is match.
    But it is done using OCR1A register.
    Is it possible to select OCR1B as TOP with CTC option???

  • @princegautam8504
    @princegautam8504 6 лет назад

    I want to know if its possible to change the value of OCR1A when the timer is working.
    What i want is to generate Pulse train in which the ON time is fixed and the OFF time changes as per the formula that i already have.
    Is it possible to do this using your explanation of timer in this video.(I think it is) but i don't exactly know which register work with.
    Thanks for the awesome explanation

  • @danny117hd
    @danny117hd 4 года назад

    I liked how above this was. I got lost when you were setting bits on with shift. There has to be an easier way. Like a hex number maybe or simply HIGH. My Question is Shouldn't Tload be not zero but the time it takes to execute the interrupt code?

    • @Gipsy_T.
      @Gipsy_T. 2 года назад

      Yeah i got lost too, u can use the operator |= to do the same thing bit by bit.
      For example timer 5 on arduino mega:
      TCCR5B=0; // You have to clear the register first!!
      TCCR5B |= 0b00001010; /*the last 3 bits set the internal clock with a 8 preescaler, the previous bit sets the CTC mode
      0b00001(010) this bits set the preescaler
      0b0000(1)010 this bit sets the ctc mode*/

  • @MrSirPain
    @MrSirPain 2 года назад

    I have a ned for 3 timer interrupts. Is this possible? I am using a SAMD board.

  • @hasemali7799
    @hasemali7799 6 лет назад +1

    thanks sparkfun you are doing a great job. you guys are the best of the best

  • @sayfalattar9515
    @sayfalattar9515 5 лет назад

    Can I use both compare registers A And B at the same time to creat two interrupts at different intervals ?

  • @oncom81
    @oncom81 3 года назад

    so, if I wanna toggle led every 1s,
    change like this : const uint16_t t1_comp = 62500;
    and disable interrupt with change value OCCIEA like this: TIMSK1 = (0

  • @BadRobotXIII
    @BadRobotXIII 4 года назад

    What documentation did you find Arduino timer uses'? i would like to find out what the atmega2560 timers are used for so i can utilize the correct one for my application.

  • @pfow2006
    @pfow2006 6 лет назад

    wholly smokes that definitely over my head, was following well, comprehending ok for first third of video, but by 12 minutes i could smell smoke, but great video, hope it is here to revisit when I get more advanced, was good to touch on the more rudimentary operation of the 328p

  • @DieselBoulder
    @DieselBoulder 3 года назад

    holy crap. This was amazing!

  • @idogendel
    @idogendel 6 лет назад +10

    And before we know it, we'll be using the Atmel Studio IDE ;-)

    • @SpeccyMan
      @SpeccyMan 6 лет назад +1

      Why use that bloatfest when you could use Great Cow BASIC?

    • @idogendel
      @idogendel 6 лет назад

      Actually I'm a fan of Pascal :-)

    • @ShawnHymel
      @ShawnHymel 6 лет назад +1

      I actually enjoyed Atmel Studio when I used it a few years ago. I'm just really sad that it's Windows-only :(

    • @idogendel
      @idogendel 6 лет назад

      It's ok to love Microsoft nowadays, because with Google and everything they're totally the underdog ;-)

    • @DCFusor
      @DCFusor 6 лет назад

      No, just because one guy ain't up to snuff, doesn't mean the other guy is OK - true also of politics. Maybe both are a problem.

  • @Pendududesign
    @Pendududesign 4 года назад

    Hi, thank you for this great video. You are writing a ISR function but where did you find this information ? from the arduino documentation ? I’m not able to find this. You are also using a variable named TIMER1_COMPA_vect , but how you find it ? Even for the sei() function. Also what’s AVR. could you make another video about it ?

  • @ilyashick3178
    @ilyashick3178 4 года назад

    First, delay(500) does not need in loop.Just modification of tl_comp = 31250 is 0.5 sec; multiplication by 2 is 1 sec, or division to 2 is 125 millisecond.

  • @agusmakki01
    @agusmakki01 6 лет назад +1

    still confuse about icr mode

  • @yohanchristian2988
    @yohanchristian2988 5 лет назад

    just curious why use &=for CS11 and CS10 while using |= on CS12? i know one is compound bitwise and while the other are compound bitwise or. but i have tried a couple of variation of the bitwise but it didnt change anything

  • @RovanRCTube
    @RovanRCTube 6 лет назад

    I have searched the Internet high and low. I am looking for information on how to use the i2c pins on this sparkfun blackboard Ad4 -sad and ad5-scl as I would use a4 and a5 on the Arduino? Can’t find any instruction sheets or Arduino code anywhere. I use i2c on real Arduino without problems.

  • @kennethstauffer9220
    @kennethstauffer9220 5 лет назад

    thanks, i was curious if arduino allowed for direct programming of the ATMega chip, instead of their silly API.

  • @corri303
    @corri303 5 лет назад +1

    Should have reset TCCR1B as well. Didn't work here at first because of that. Still great tutorial!!!

  • @OneIdeaTooMany
    @OneIdeaTooMany 4 года назад

    I feel like timers would be such a useful thing but geez it's taking a while to figure out which timer to use, whether I've got anything that's dependant on it which would be affected by adjusting the prescaler etc

  • @reshadrei1788
    @reshadrei1788 3 года назад

    Please make a video about Pointer Access Operators

  • @Gipsy_T.
    @Gipsy_T. 2 года назад

    For those (like myself) that dont understand the

    • @Gipsy_T.
      @Gipsy_T. 2 года назад

      I tried it with the = operator and still works example: TCCR5B = 0b00001010; with this method u dont have to clear the register

    • @Milangasor
      @Milangasor 2 года назад

      @@Gipsy_T. i guess it overwrite it anyway

  • @mayankshigaonker7725
    @mayankshigaonker7725 5 лет назад

    Yeah I want to see more fun videos like these!!

  • @brunolinharesmiranda
    @brunolinharesmiranda 3 года назад

    Isn't the AVR internal frequency 8 MHz?
    Why did you stated 16 MHz?

  • @RovanRCTube
    @RovanRCTube 6 лет назад +2

    Good tutorial, but it would be helpful if text was larger on sketches.

  • @arjunremesh1395
    @arjunremesh1395 6 лет назад

    When I write server program for wify using arduino ide in practical case I experience the serveris not active once the input current is not available for a while and then restarted .Can you please explain a good code for wify server using arduino ide using registers .

  • @jordanmusleh6305
    @jordanmusleh6305 3 года назад

    Please help me I can’t find out how to do this ..!!

  • @freddy7phil
    @freddy7phil 6 лет назад +2

    Love the intro!

  • @rubabvlogs1843
    @rubabvlogs1843 6 лет назад +7

    nice tutorial..keep it up sir..

  • @sergiourquijo4000
    @sergiourquijo4000 4 года назад

    Where can i get the manual?

  • @adaminsanoff
    @adaminsanoff 5 лет назад

    One couldn't explain it better.

  • @jeffreylebowski4927
    @jeffreylebowski4927 5 лет назад

    FYI: The Crystal Resonator on the UNO and MEGA is only connected to the little microcontroller, that is handling the USB communication.
    The main Microcontrollers (328 and 2560) have FAR LESS ACCURATE 16Mhz ceramic resonators as clocks!

  • @abelashenafi6291
    @abelashenafi6291 5 лет назад +1

    video worth subscribing!!

  • @sameqy
    @sameqy 6 лет назад

    how does timer1 affect the servo functions? is it because of the delays being too big?

    • @mykalimba
      @mykalimba 5 лет назад

      I would imagine that the servo functions are affected because they rely on a specific frequency from timer1 (as configured in its default state) to control the timing of signals sent to the servos. When that timing is changed, the servo functions can't operate normally.

  • @skrame01
    @skrame01 6 лет назад

    can you do tutorials on the samd21? its very different.

  • @cybercrazy1059
    @cybercrazy1059 6 лет назад

    Whow, that tutorial is a very good one. Thank you very much!

  • @Omarbg95
    @Omarbg95 6 лет назад

    Please make a video using PWM with registers

  • @rameshrathod6960
    @rameshrathod6960 6 лет назад

    (shawn hymel sir help me) iam trying to measuring the freq and time period for square wave(iam using input capture metrhod), i connect signal to digital pin no 8 i.e ICP1. TCNT1 is automatically stored in ICR1 register while rising Edge, im setting for Falling edge TCNT1 is stored in ICP1 reg again for rising edge(means here is it taking for 1 cycle 0 to 65535 ??). how this is working am not getting please any one explain or send me any videos link iam struggling from past 2 weeks pls help me....
    rising edge means TCNT1 is incrementing upto 65535 or ??
    then what values TCNT1 is taking during falling edge.....

  • @frankliu1029
    @frankliu1029 3 года назад

    good tutorials, one zan!

  • @rafaeldiaz6308
    @rafaeldiaz6308 6 лет назад

    Excellent video.

  • @codeman99-dev
    @codeman99-dev 4 года назад +1

    11:25 Because it is so hard to shift around a base 16 number. I mean, I love convenience, but the tutorial up to this point is anything but that.

  • @drdanoosh
    @drdanoosh Год назад

    I don't understand, what's the point?
    What does this accomplish?

  • @satviksharma1146
    @satviksharma1146 5 лет назад +1

    great video. Thanks a lot.

  • @jeanvermette1225
    @jeanvermette1225 5 лет назад

    You saved my life

  • @lrhpro688
    @lrhpro688 6 лет назад

    Hi ,
    I have a problem in a code that uses IRreciver reading to toggle in switch statement I have 3 cases the first 2 cases work great with timer interrupt because they're simple just turning on/off a led , but the third one it's not responding to the interupt because it's a hell of a long cooooode , is there any way using timer interrupts to get out from that case even if the code still running ?
    void setup()
    {
    //Setup pin modes
    pinMode(buzzerPin, OUTPUT);
    pinMode(ledPin3,OUTPUT);
    pinMode(ledPin1, OUTPUT);
    pinMode(ledPin2, OUTPUT);
    pinMode(redPin,OUTPUT);
    Serial.begin(9600);
    irrecv.enableIRIn(); // Start the receiver
    Timer1.initialize(10000);
    Timer1.attachInterrupt(Iremote);
    }
    void loop()
    {
    switch(results.value){
    case 0xFFE21D : digitalWrite(redPin,HIGH);

    break;
    case 0xFFA25D : digitalWrite(redPin,LOW);
    break ;
    case 0xFF02FD: digitalWrite(redPin,LOW);

    //Play first section
    firstSection();
    //Play second section
    secondSection();
    //Variant 1
    beep(f, 250);
    beep(gS, 500);
    beep(f, 350);
    beep(a, 125);
    beep(cH, 500);
    beep(a, 375);
    beep(cH, 125);
    beep(eH, 650);
    delay(500);
    //Repeat second section
    secondSection();
    //Variant 2
    beep(f, 250);
    beep(gS, 500);
    beep(f, 375);
    beep(cH, 125);
    beep(a, 500);
    beep(f, 375);
    beep(cH, 125);
    beep(a, 650);
    delay(1000);
    break ;
    }}
    void Iremote(){
    if (irrecv.decode(&results)) {
    Serial.println(results.value,HEX);
    irrecv.resume();
    return ;
    }
    thanks in advance .

    • @maxduncan7090
      @maxduncan7090 5 лет назад

      You shoud not use Serial inside of interrupts. it would be better to make your interrupt as short as possible. An example would be to set a flag with your interupt if your parameter is met. Then let your loop code check for the flag and run the code there. you should also try and get rid of the delays they can avoided with interrupts and just doing stuff that is needed to be done while just watching the clock. Here is a link that has an serial in the interrupt. arduino.stackexchange.com/questions/46595/sending-serial-data-in-an-interrupt

  • @ericklestrange6255
    @ericklestrange6255 4 года назад

    funny, cute, im 18 secs in and already hooked

  • @haokim6997
    @haokim6997 6 лет назад

    Nice tutorial. Thanks!

  • @jcjensenllc
    @jcjensenllc 4 года назад

    Wow. Exact answer to a problem I had.

  • @aadishmanrai8408
    @aadishmanrai8408 5 лет назад

    Can you please write a code that i can upload in Arduino, I want a Small beep sound at 30mins, 1hr, 1:30hr, 2hr(all optional )

  • @FreddyBNL
    @FreddyBNL 6 лет назад +1

    Is the code somewhere to be found or am I overlooking something? Great explanation btw. Very, very good. 👍

    • @ShawnHymel
      @ShawnHymel 6 лет назад +1

      Sorry for the late response. It isn't listed in the description, but it can be found here: gist.github.com/ShawnHymel/d36e527928994150f5fc3cba20dd2161

  • @cursodeinnovaciontecnologi4912
    @cursodeinnovaciontecnologi4912 4 года назад

    You should make more videos!!!!

  • @jasonsammons9
    @jasonsammons9 3 года назад

    great video

  • @listar1210
    @listar1210 3 года назад

    excuse me, anyone to help my theses ?
    i need prepare frequency sampling at my arduino uno as 1000Hz
    i use this program but cant sharp at 1000Hz
    can you help me ?
    actually i check it on osiloscop
    const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
    const int analogOutPin = 3; // Analog output pin that the LED is attached to
    int sensorValue = 0; // value read from the pot
    int outputValue = 0; // value output to the PWM (analog out)
    void setup() {
    // initialize serial communications at 9600 bps:
    pinMode(3,OUTPUT);
    Serial.begin(9600);
    noInterrupts(); // disable all interrupts
    TCCR1A = 0;
    TCCR1B = 0;
    //TCNT1 = 65484;// preload timer 65536-16MHz/256/1200Hz
    //TCNT1 = 65411;// preload timer 65536-16MHz/256/500Hz
    TCNT1 = 65473;// preload timer 65536-16MHz/256/1000Hz
    //TCNT1 = 65503;// preload timer 65536-16MHz/256/2000Hz
    //TCNT1 = 34286; // preload timer 65536-16MHz/256/2Hz
    TCCR1B |= (1

  • @genelim9504
    @genelim9504 6 лет назад

    Awesome video

  • @geoffhoweth
    @geoffhoweth 6 лет назад +2

    OK so this is why your product be a phone 'washer, ac ETC... blows up are stop working after the warranty expires. The kill code gets activated and that's when your phone starts to get really hot (am i the only one who has noticed that ?) Because the manufacturer has put in a kill code(starts over clock of cpu in the device ) to destroy that product so you have to buy the latest and greatest and pay more. Simple but yet very effective. Not to mention they encrypt the chip so you cant see the code on it to prove this theory.

  • @RovanRCTube
    @RovanRCTube 6 лет назад

    It would be nice if you numbered your lessons.

  • @djfisjtik
    @djfisjtik 5 лет назад

    Great comic timing. Interesting subject.

  • @dshshajskj6143
    @dshshajskj6143 2 года назад

    can u plz help me generate 1khz sine wave using arduino i need it asap i will be hugely grateful

  • @ThierryC2373
    @ThierryC2373 6 месяцев назад

    Wow this is more than timer interrupts, this is advanced Arduino registers timer interrupts. Not for beginners. Unfortunately, the video does not talk about timed tasks during an interruption.

  • @nurbekhalikulov8867
    @nurbekhalikulov8867 5 лет назад

    AMAZING

  • @scottroelker4431
    @scottroelker4431 6 лет назад +1

    The code needs to be cleared please, it is too blurry and too small.

  • @charmonnicolaih649
    @charmonnicolaih649 5 лет назад

    This made me feel smart hehe

  • @pahvalrehljkov
    @pahvalrehljkov 6 лет назад

    youre amazing...

  • @gudimetlakowshik3617
    @gudimetlakowshik3617 3 года назад

    You can do, TCCR1B |= (1

  • @mitchellhw2006
    @mitchellhw2006 Год назад

    This would have made more sense if you had told the viewers you were using Compound Operators or just written it out in longhand format. Still a good video though.