O'Reilly logo

Arduino Essentials by Francis Perea

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The complete example code

There is nothing really new in the code that we will use for this example. We will, just like in the previous one, simply read the digital input corresponding to the phototransistor and only if it is a HIGH value, which means it is not receiving any light and thus not conducting, will we make the output LED blink.

Once again, just for the sake of simplicity, and given that now we know that we don't really need to store the value read with digitalRead() and we can simply call the functions inside the if condition, I have opted this time to save up this variable and simplify even a little more of the code:

/* Chapter 05 - Sensing the real world through digital inputs Optical coin detector By Francis Perea for Packt Publishing ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required