Reprogramming the Simon Says with Arduino Linz Craig
- Slides: 31
Re-programming the Simon Says with Arduino Linz Craig, Brian Huang
Agenda • • About us / Introductions Software Installation What can it do? Who cares? Blink Sketch Disco Lights Using Variables If() statement reading button. Press Analog Sensors Fading Making Sound
About Us Spark. Fun Electronics is all about creation, innovation and sharing information. We want to get you excited about cutting edge electronics technology with our hands on educational kits.
Arduino Board “Strong Friend” Created in Ivrea, Italy in 2005 by Massimo Banzi & David Cuartielles Open Source Hardware Atmel Processor Coding is accessible (C++, Processing, Mod. Kit and Mini. Bloq)
Arduino Software Installation Open Source Free Available on-line with resources at: www. arduino. cc
What can it do? • Great for prototyping ideas • Access to multiple I/O • Drive motors, turn on lights, trigger controls. • Low Power requirements • Flexible / Open-source
Who cares? Hackers / Makers Engineers Artists Musicians Kids! Teachers!! You!!!
Setup Board Type Tools → Board → Arduino Uno
Setup Serial COM Port Tools → Serial Port → Notes: PC – Highest COM # Mac – /dev/tty. usbserial-A####xxx
Analog and Digital • All Arduino signals are either Analog or Digital • All computers including Arduino, only understand Digital • It is important to understand the difference between Analog and Digital signals since Analog signals require an Analog to Digital conversion
Input vs. Output Everything is referenced from the perspective of the microcontroller. Inputs is a signal going into the board. Output is any signal exiting an electrical system • Almost all systems that use physical computing will have some form of output • Often – Outputs include LEDs, a motor, a servo, a piezo element, a relay and an RGB LED
upload Basic Program Two required routines / methods / functions: void setup() { // runs once } void loop() { // repeats forever!!! }
Let’s get to hacking… Project #1 – Blink “Hello World” of Physical Computing Psuedo-code – how should this work? Turn LED ON Wait Turn LED OFF Wait Rinse & Repeat
Three commands to know… pin. Mode(pin, INPUT/OUTPUT); ex: pin. Mode(13, OUTPUT); digital. Write(pin, HIGH/LOW); ex: digital. Write(13, HIGH); delay(time_ms); ex: delay(2500);
LED Pin Configurations LED 1 = ~3; LED 2 = ~5; LED 3 = ~10; LED 4 = 13; 10 3 13 5 Can you figure out which LED is tied to which pin? Write down a few notes in your notebook!
Output is always Digital To output a signal that pretends to be Analog use this code: analog. Write (pin. Number, value ); Where pin is one of the analog output pins: 3, 5, 6, 9, 10, 11 Where value is a number ranging from: 0 – 255.
Output is always Digital (ON or OFF) Using a Digital signal that pretends to be an Analog signal is called Pulse Width Modulation (PWM) By varying the duty cycle, we can “fake” an analog signal output. PWM is available on Arduino pins # 3, 5, 6, 9, 10, and 11 P. W. M. Signal @ 25% SIMON_2 b_BLINK P. W. M. Signal @ 75% P. W. M. Signal rising
Using Variables To clean-up code, for read-ability, and flexibility – we can create placeholders in code. Example: int led. Pin = 3; void setup(){ pin. Mode(led. Pin, OUTPUT); } void loop(){ digital. Write(led. Pin, HIGH); }
Digital Input int button_state = digital. Read(Button. Pin); Value will be either: HIGH or LOW
Reading a button press Button Input is normally HIGH – when you press it, you pull it LOW. The Code: int button. Press = digital. Read(2);
Activating the Internal Pull-up Resistor pin. Mode(pin, INPUT_PULLUP); ex: pin. Mode(2, INPUT_PULLUP); Notes: BUTTON 1 = 2; BUTTON 2 = 6; BUTTON 3 = 9; BUTTON 4 = 12;
Button Pin Configurations BUTTON 1 = 2; BUTTON 2 = 6; BUTTON 3 = 9; BUTTON 4 = 12; 9 2 12 6 Can you figure out which Button is tied to which pin? Write down a few notes in your notebook!
Conditional Statements If… General Use if(condition) Example if(button_State==HIGH) { { // do this digital. Write(led. Pin, HIGH); delay(300); } digital. Write(led. Pin, LOW); delay(300); }
Digital Input • To connect digital input to your Arduino use Digital Pins # 0 – 13 (Although pins # 0 & 1 are also used for serial) • Digital Input needs a pin. Mode command: pin. Mode ( pin. Number, INPUT ); Make sure to use caps for INPUT • To get a digital reading: digital. Read ( pin. Number ); • Digital Input values are only HIGH (On) or LOW (Off)
Last bit… the buzzer SIMON_3_BUZZER Final command to know: tone(pin, freq, duration); pin – the OUTPUT pin the buzzer is connected to. freq – unsigned int (0 … 65, 535) duration – unsigned long (0 … 2^32 - 1)
Buzzer Pins The Buzzer is connected between pins D 4 and D 7. You must set both pins as OUTPUTs – pin. Mode(4, OUTPUT); pin. Mode(7, OUTPUT); Use tone(4, 440); to generate a 440 Hz sound.
Musical Notes / Frequencies Note Frequency (Hz) C 4 C#4/Db 4 D#4/Eb 4 E 4 F#4/Gb 4 G#4/Ab 4 A#4/Bb 4 B 4 261 277 293 311 329 349 369 392 415 440 466 493 C 5 C#5/Db 5 D#5/Eb 5 E 5 F#5/Gb 5 G#5/Ab 5 A#5/Bb 5 B 5 523 554 587 622 659 698 739 783 830 880 932 987
Simon Disco. Mode • Array variables • custom functions • • buzz(tone_id); change_led();
Questions?
www. sparkfun. com 6175 Longbow Drive, Suite 200 Boulder, Colorado 80301
- Simon says arduino with buzzer
- Tpr simon says
- Simon says gent
- Kanalisierung linz
- Wolfhard klein
- Linz ag kanal
- Akh schulterambulanz
- Pflegeberatung linz-land
- Folienpool linz
- Linz ist die hauptstadt von
- Quá trình desamine hóa có thể tạo ra
- Vẽ hình chiếu vuông góc của vật thể sau
- Công thức tính độ biến thiên đông lượng
- Thế nào là mạng điện lắp đặt kiểu nổi
- Dot
- Bổ thể
- Vẽ hình chiếu đứng bằng cạnh của vật thể
- Phản ứng thế ankan
- Môn thể thao bắt đầu bằng chữ đua
- Khi nào hổ mẹ dạy hổ con săn mồi
- điện thế nghỉ
- Một số thể thơ truyền thống
- Nguyên nhân của sự mỏi cơ sinh 8
- Trời xanh đây là của chúng ta thể thơ
- Số nguyên tố là gì
- Thiếu nhi thế giới liên hoan
- Fecboak
- Tỉ lệ cơ thể trẻ em
- Các châu lục và đại dương trên thế giới
- Thế nào là hệ số cao nhất
- Hệ hô hấp
- Tư thế ngồi viết