Lab 7 Basic 1: Game of Memory

Slides:



Advertisements
Similar presentations
Wireless Cue Light Project
Advertisements

Button Input: On/off state change Living with the Lab Gerald Recktenwald Portland State University
EMS1EP Lecture 6 Digital Inputs
EMS1EP Lecture 4 Intro to Programming Dr. Robert Ross.
Lab7: Introduction to Arduino
Chung-Ta King National Tsing Hua University
Embedded Sumo 1T4 – 1T5 UTRA.
Panasonic EVE-KC2F2024B 24 pulses per revolution 6mm diameter flattened output shaft output type: quadrature (incremental) minimum life: 15,000 rotations.
Introduction to Arduino Prepared by R. Lamond.  “Arduino is an open-source electronics prototyping platform based on flexible, easy- to-use hardware.
Arduino Part 2 Topics: Serial Communication Programming Constructs: functions, loops and conditionals Digital Input.
DPNM Lab., POSTECH 1/25 CS490K - Internet of Things (IoT) Jonghwan Hyun DPNM Lab. Department of Computer Science and Engineering, POSTECH
Intro to Arduino Programming. Draw your circuits before you build them From Arduino 330 Ohm From Arduino 330 Ohm From Arduino 330 Ohm.
Khaled A. Al-Utaibi  The Push Button  Interfacing Push Buttons to Arduino  Programming Digital Inputs  Working with “Bouncy”
LAB 8: Program Design Pattern and Software Architecture
Introduction to Sensor Technology Week Five Adam Taylor
LECTURE 2 – INPUTS THIS LECTURE WILL INTRODUCE HOW TO INPUT SIGNALS INTO AN ARDUINO.
ARDUINO 1. Basics  Comments  /* * Blink * * The basic Arduino example. Turns on an LED on for one second, * then off for one second, and so on... We.
Basic Circuits – Lab 5 Wireless Networking Xmedia Spring 2011.
INTERNET OF EVERYTHING SDU 2016 Week 4. Simple Digital and Analog Inputs  The Arduino’s ability to sense digital and analog inputs allows it to respond.
Embedded Programming and Robotics Lesson 11 Arduino Interrupts 1.
Microcontroller basics Embedded systems for mortals.
Microcontroller basics Embedded systems for mortals.
ME 120: Arduino Programming Arduino Programming Part II ME 120 Mechanical and Materials Engineering Portland State University
Arduino + Bluetooth TYWu. Connection Arduino + Bluetooth Module.
Harpeth Hall Jan 2016 Introduction to Arduino Prepared for Harpeth Hall Winterim January 2016.
Introduction In this lab , we will learn
Arduino.
Outline Introduction to Arduino UNO Programming environment setup GPIO
Introduction In this lab , we will learn
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
Outline Introduction to digital-to-analog converter (DAC)
Assist. Prof. Rassim Suliyev - SDU 2017
Assist. Prof. Rassim Suliyev - SDU 2017
CS4101 嵌入式系統概論 General Purpose IO
More on LED’s with Arduino
Samsung Ex-link RS-232 Control
Samsung Ex-link RS-232 Control
Microcontroller basics
CS4101 Introduction to Embedded Systems Lab 10: Tasks and Scheduling
CS4101 Introduction to Embedded Systems Lab 6: Low-Power Optimization
CS4101 Introduction to Embedded Systems Lab 1: MSP430 LaunchPad IDE
Wireless Cue Light Project
Arduino Programming Part II
Microcontroller basics
UTA010 : Engineering Design – II
Welcome to Arduino A Microcontroller.
Get Your Project Started with Arduino
CS4101 Introduction to Embedded Systems Lab 1: General Purpose IO
Prof. Chung-Ta King Department of Computer Science
Samsung Ex-link RS-232 Control
CS4101 嵌入式系統概論 General Purpose IO
Arduino Part 1 Topics: Microcontrollers Programming Basics
INC 161 , CPE 100 Computer Programming
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 2: Timer and Clock Prof. Chung-Ta King Department of Computer Science National.
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 3: Interrupt Prof. Chung-Ta King Department of Computer Science National Tsing.
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 6: Serial Communication Prof. Chung-Ta King Department of Computer Science National.
Roller Coaster Design Project
CSCI1600: Embedded and Real Time Software
Intro to the Arduino Topics: The Arduino Digital IO
1 Code
CS-4540 Robotics - Lab 05 Switch inputs to the Arduino Uno
CS4101 Introduction to Embedded Systems Lab 8: Arduino DAC and PWM
Topics: Programming Constructs: loops & conditionals Digital Input
Programming 2: The Arduino IDE & First Sketches
Lab 1. Introduction to the DE2 Board
CS4101 Introduction to Embedded Systems Lab 2: Basic IO and Timer
Prof. Chung-Ta King Department of Computer Science
CSCI1600: Embedded and Real Time Software
Arduino Leonardo Setup
Interrupts.
Presentation transcript:

CS4101 Introduction to Embedded Systems Lab 7: Arduino Basics Prof. Chung-Ta King Department of Computer Science National Tsing Hua University, Taiwan

Lab 7 Basic 1: Game of Memory In this lab, you are going to develop a round-based game to test the memory of the player. The game requires a button, a red LED, and a green LED. In each round, the red LED is on for x seconds, where x is set randomly between 1 to 5 seconds, and then off. The player counts the duration that the red LED is on and then presses the button for the same amount of time. If the difference between the button-press time and x is within a margin y seconds, then the player wins this round and the green LED is blinked twice (0.5 second on and off). Otherwise, the red LED is blinked 5 times (0.2 second on and off).

Lab 7 Basic 1: (cont.) At the end of each round, transfer the result to the PC, including the LED on time and button-press time. The PC displays the accumulated counts of wins and loses, and the LED on time and button-press time of the last round. All the events must be handled by interrupts.

Serial Communication to/from PC Arduino UNO has one serial port, called UART or USART The serial port uses TX (pin 1) and RX (pin 0) to transmit and receive data

Serial Communication to/from PC The Arduino IDE has a feature, called “Serial Monitor”, which is a separate pop-up window that acts as a terminal to communicate with the Arduino UNO by receiving and sending serial data Arduino’s serial library supports serial communication Serial.begin() - start serial port and set baud rate Serial.println() - transmit the data to PC Serial.read() - receive the data from PC

Sample Code for Serial Communication void setup() { // Open serial port, set baud rate Serial.begin(9600); int value = 65; // data to be transmitted Serial.println(value); // print “65” Serial.println(value, DEC); // same as above Serial.println(value, HEX); // print “41” Serial.println(value, BIN); // print “01000001” Serial.println(value, BYTE); // print “A” } void loop() { ...

Sample Code for Serial Communication

Pushbutton Switch Pushbutton internal: Button connection: 10K ohm resistor in series LED connection: 220 ohm resistor in series (http://www.ladyada.net/learn/arduino/lesson5.html)

Pushbutton Bounce Problem Push buttons often generate spurious open/close transitions when pressed due to mechanical and physical issues These transitions may be read as multiple presses in a very short time, which cause the program to confuse. The problem can be solved with hardware or software. A simple idea for debouncing: check twice in a short period of time to make sure the pushbutton is definitely pressed. (http://www.protostack.com/blog/2010/03/debouncing-a-switch/)

Sample Code for Debouncing int led_pin = 13; int button_int = 0; // Interrupt 0 is on pin 2 int toggle_on = false; // Button click switches LED void setup() { attachInterrupt(button_int, handle_click, RISING); // Register handler } void loop() { if (toggle_on) { digitWrite(led_pin, HIGH); } else { digitWrite(led_pin, LOW);

Sample Code for Debouncing void handle_click() { static unsigned long last_int_time = 0; unsigned long int_time = millis(); // Read the clock if (int_time - last_int_time > 200 ) { // Ignore when < 200 msec toggle_on = !toggle_on; } last_int_time = int_time;