Top Banner
Arduino Boot Camp! Not your usual basic Arduino workshop!
89

Arduino Boot Camp Pitch Slides

Apr 14, 2017

Download

Education

Mithi Sevilla
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Arduino Boot Camp Pitch Slides

Arduino Boot Camp!Not your usual basic Arduino workshop!

Page 2: Arduino Boot Camp Pitch Slides

Hello! I am Mithi!

Page 3: Arduino Boot Camp Pitch Slides

I graduated from BS Electronics and Communication Engineering in UP Diliman sometime ago

I am also one of the co-founders of Nanica.io, a young and small robotics education start-up.

Hello! I am Mithi!

Page 4: Arduino Boot Camp Pitch Slides

Here are a few thingswe do at Nanica.io(it’s video time, guys!)

Page 5: Arduino Boot Camp Pitch Slides

Our most recentproject isArduino Boot Camp: A Different Approach!

Page 6: Arduino Boot Camp Pitch Slides

I designed it with <3 (love) for beginners and intermediate Arduino users

Page 7: Arduino Boot Camp Pitch Slides

You can find it at:http://ArduinoBootCamp.xyz

Page 8: Arduino Boot Camp Pitch Slides

It’s NOT your usual Basic Arduino Workshop >_<

Page 9: Arduino Boot Camp Pitch Slides

How?

Page 10: Arduino Boot Camp Pitch Slides

Well, let me give you an example.

Page 11: Arduino Boot Camp Pitch Slides

Usually, in beginner workshops, you are taught the following:

Page 12: Arduino Boot Camp Pitch Slides

ONE:How to blink an LED

Page 13: Arduino Boot Camp Pitch Slides

TWO:How to blink an LED without delay()

Page 14: Arduino Boot Camp Pitch Slides

THREE:How to make a breathing LED

Page 15: Arduino Boot Camp Pitch Slides

FOUR:How to sweep a servo back and forth

Page 16: Arduino Boot Camp Pitch Slides

FIVE:How to light an LED with a debouncedbutton

Page 17: Arduino Boot Camp Pitch Slides

This is how the official Arduino website teaches you how to blink an LED...

Page 18: Arduino Boot Camp Pitch Slides

digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(13, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second

Page 19: Arduino Boot Camp Pitch Slides

We help you learn how you can do this instead:

Page 20: Arduino Boot Camp Pitch Slides

led.Toggle();delay(1000);

Page 21: Arduino Boot Camp Pitch Slides

This is how the official Arduino website teaches you how to blink an LED without delay()...

Page 22: Arduino Boot Camp Pitch Slides

unsigned long currentMillis = millis(); if(currentMillis - previousMillis >= interval){

previousMillis = currentMillis;

if (ledState == LOW) ledState = HIGH; else ledState = LOW;

digitalWrite(ledPin, ledState);}

Page 23: Arduino Boot Camp Pitch Slides

We help you learn how you can do this instead:

Page 24: Arduino Boot Camp Pitch Slides

if(metronome.Tick()) led.Toggle();

Page 25: Arduino Boot Camp Pitch Slides

This is how the official Arduino website teaches you how to make a breathing LED...

Page 26: Arduino Boot Camp Pitch Slides

int fadeValue;

for(fadeValue=0; fadeValue<=255; fadeValue+=5){ analogWrite(ledPin, fadeValue); delay(30);}

for(fadeValue=255; fadeValue>=0; fadeValue-=5){ analogWrite(ledPin, fadeValue); delay(30);}

Page 27: Arduino Boot Camp Pitch Slides

We help you learn how you can do this instead:

Page 28: Arduino Boot Camp Pitch Slides

led.Set(sweeper.Next(metronome.Tick()));

Page 29: Arduino Boot Camp Pitch Slides

This is how the official Arduino website teaches you how to sweep a servo...

Page 30: Arduino Boot Camp Pitch Slides

for (pos = 0; pos <= 180; pos += 1) { servo.write(pos); delay(15); }

for (pos = 180; pos >= 0; pos -= 1) { servo.write(pos); delay(15); }

Page 31: Arduino Boot Camp Pitch Slides

We help you learn how you can do this instead:

Page 32: Arduino Boot Camp Pitch Slides

servo.write(sweeper.Next(metronome.Tick()));

Page 33: Arduino Boot Camp Pitch Slides

This is how the official Arduino website teaches youhow to light an LED with a debounced button...

Page 34: Arduino Boot Camp Pitch Slides

int reading = digitalRead(buttonPin);if (reading != lastButtonState) { lastDebounceTime = millis();}if ((millis() - lastDebounceTime) > debounceDelay) { if (reading != buttonState) { buttonState = reading; if (buttonState == HIGH) ledState = !ledState; }}digitalWrite(ledPin, ledState);lastButtonState = reading;

Page 35: Arduino Boot Camp Pitch Slides

We help you learn how you can do this instead:

Page 36: Arduino Boot Camp Pitch Slides

button.Pressed() ? led.On() : led.Off();

Page 37: Arduino Boot Camp Pitch Slides

Basically, it’s different because it emphasizes the following things immediately:

Page 38: Arduino Boot Camp Pitch Slides

ONE: CLEAN READABLE CODE

Page 39: Arduino Boot Camp Pitch Slides

TWO: BASIC OBJECT-ORIENTED DESIGN

Page 40: Arduino Boot Camp Pitch Slides

THREE: REDUCED USAGE OF delay()so you can multi-task anytime.

Page 41: Arduino Boot Camp Pitch Slides

BUT HOW DO YOU DO THAT????!?

Page 42: Arduino Boot Camp Pitch Slides

The obvious message here is how you can use the power of OOP design thinking...

Page 43: Arduino Boot Camp Pitch Slides

... to abstract implementation details...

Page 44: Arduino Boot Camp Pitch Slides

... so that you can focus at the things you want to do.

Page 45: Arduino Boot Camp Pitch Slides

You get the beneficial side-effects as well:

Page 46: Arduino Boot Camp Pitch Slides

Code that is easy to understand.

Page 47: Arduino Boot Camp Pitch Slides

Code that is easy to debug.

Page 48: Arduino Boot Camp Pitch Slides

Code that is multi-tasking ready.

Page 49: Arduino Boot Camp Pitch Slides

Code that is scalable.Easily add as many buttons and LEDs as the Arduino can allow.

Page 50: Arduino Boot Camp Pitch Slides

Code that allows more complex behavior.Add more features and functions without overwhelming yourself.

Page 51: Arduino Boot Camp Pitch Slides

BUT… HOW DO YOU DO THAT EXACTLY ????!?

Page 52: Arduino Boot Camp Pitch Slides

The first step is to identify the OBVIOUS objects

Page 53: Arduino Boot Camp Pitch Slides

LED, BUTTON, and SERVO (the Arduino already has a built-in servo class in one of its libraries)

Page 54: Arduino Boot Camp Pitch Slides

DigitalOutput led;

led.New(int pin);led.On();led.Off();led.Toggle();led.Set(int brightness);

Page 55: Arduino Boot Camp Pitch Slides

Button button;

button.New(pin, debounceTime);bool state = button.Pressed();

Page 56: Arduino Boot Camp Pitch Slides

The next step is to identify not so obvious objects

Page 57: Arduino Boot Camp Pitch Slides

sweeper.New(x1, x2, inc, type); sweeper.Next(0/1);

// type = BACKANDFORTH/NORMAL/* if 0, returns current state** if 1, updates to and return ** next state */

Page 58: Arduino Boot Camp Pitch Slides

metronome.New(milliSeconds)bool hasTicked= metronome.Tick()

Page 59: Arduino Boot Camp Pitch Slides

You can use sweeper in myriad applications…not just servos and LEDs...

Page 60: Arduino Boot Camp Pitch Slides

You can use this to toggle buttons,play tunes, do countdowns...

Page 61: Arduino Boot Camp Pitch Slides

and even do away with long subroutines because of for-loops.

Page 62: Arduino Boot Camp Pitch Slides

Using metronome instead of delay(), you get a more readable code that’s even multi-tasking ready.

Page 63: Arduino Boot Camp Pitch Slides

You can even sweep multiple servos….

Page 64: Arduino Boot Camp Pitch Slides

...blink and sweep multiple LEDs...

Page 65: Arduino Boot Camp Pitch Slides

...(simultaneously, and at different rates )...

Page 66: Arduino Boot Camp Pitch Slides

...while catching as many buttons as you wish...

Page 67: Arduino Boot Camp Pitch Slides

...without making your code a nightmare.

Page 68: Arduino Boot Camp Pitch Slides

You can even sweep multiple servos, blink and sweep multiple LEDs, (simultaneously, at different rates)while catching as many buttons as you wish, without making your code a nightmare.

Page 69: Arduino Boot Camp Pitch Slides

Awesome right?!!

Page 70: Arduino Boot Camp Pitch Slides

There’s more where that came from!

Page 71: Arduino Boot Camp Pitch Slides

Again, check it out!http://ArduinoBootCamp.xyz

Page 72: Arduino Boot Camp Pitch Slides

But wait...

Page 73: Arduino Boot Camp Pitch Slides

...what about performance?

Page 74: Arduino Boot Camp Pitch Slides

Only sacrifice readability for performance if you have measured that your code is too slow for its intended use.

Page 75: Arduino Boot Camp Pitch Slides

Correct. Beautiful. Fast. (in that order) -Elliot Rusty Harold

Page 76: Arduino Boot Camp Pitch Slides

Premature optimization is the root of all evil. -Sir Tony Hoare

Page 77: Arduino Boot Camp Pitch Slides

I hope to dispel the myth that fast code must be illegible ugly code... -Elliot Rusty Harold

Page 78: Arduino Boot Camp Pitch Slides

...improvement in beauty can also lead to improvement in speed.-Elliot Rusty Harold

Page 79: Arduino Boot Camp Pitch Slides

Hope you join ourArduino Boot Camp!!

Page 80: Arduino Boot Camp Pitch Slides

One more thing though:My code is not God ;)

Page 81: Arduino Boot Camp Pitch Slides
Page 82: Arduino Boot Camp Pitch Slides
Page 83: Arduino Boot Camp Pitch Slides
Page 84: Arduino Boot Camp Pitch Slides
Page 85: Arduino Boot Camp Pitch Slides
Page 86: Arduino Boot Camp Pitch Slides
Page 87: Arduino Boot Camp Pitch Slides
Page 88: Arduino Boot Camp Pitch Slides

Again, hope you join ourArduino Boot Camp!!

Page 89: Arduino Boot Camp Pitch Slides

And thank you for listening!

:)