220 likes | 369 Views
CSC-2700 – (3) Introduction to Robotics. Robotics Research Laboratory Louisiana State University. What we learned in last class. Diode Zener diode, Avalanche diodes, Photodiode diode Light Emitting Diode Digital Out – pin out control LED ON LED OFF LED TOGGLE LED Matrix
E N D
CSC-2700 – (3) Introduction to Robotics Robotics Research Laboratory Louisiana State University
What we learned in last class • Diode • Zener diode, Avalanche diodes,Photodiode diode • Light Emitting Diode • Digital Out – pin out control • LED ON • LED OFF • LED TOGGLE • LED Matrix • 3*3 LED matrix • 5*7 LED matrix • 8*8 LED matrix
Let make 3 * 3 LED matrix program COL1 COL2 COL3 COL1 COL2 COL3 ROW1 ROW1 ROW2 ROW2 ROW3 ROW3
Make some patterns on LED matrix COL1 COL2 COL1 COL2 COL3 COL3 ON OFF OFF ON OFF OFF 2 ROW1 OFF 1 ROW1 ON 3 2 1 3 ROW2 ROW2 5 4 ON OFF 6 5 4 6 8 7 9 8 7 9 ROW3 ON ROW3 ON COL1 COL2 COL3 OFF OFF ON ROW1 ON 2 1 3 ROW2 5 ON 4 6 8 7 9 ROW3 OFF
Topics for today • Digital Output • 8 * 8 LED matrix • Techniques for LEDs control on LED matrix • Buzzer (sound) • Basic I/O Operation – PORT • Digital input • Switch • Button • Toggle button (Flag)
Digital out – 8*8 LED dot Matrix • 64 LEDs
Techniques for LED control on LED matrix • 8 x 8 LED matrix • How many pins are needed for 8x8 LED matrix control? • One LED at each frame • How many frames are required for one picture? • What is maximum delay of one frame for one picture? (25 frames per second) • One Column or Row at each frame • How many frames are required for one picture? • What are different effects on LED?
Buzzer - sound • Tic-Tac noise • Siren • Sound pitch control • Play Song
Basic I/O Operation - PORT • Port Control Registers PORT Control Registers (A ~ G) DDRx Controls the I/O status of the PORT pins PORTx Controls the output status of pins PINx Reads the Input status of pins
Defining pins on PORT as either Input or Output DDRx Register 0 1 1 0 1 1 0 0 I/O status Controls PORTx In out out In out out In In
Defining PORTx as output DDRx Register 1 1 1 1 1 1 1 1 PORTx Register 0 1 1 0 1 1 0 0 I/O status Controls PORTx out out out out out out out out Binary : 0b01101100 Hex: 0x6C Decimal: 76 off on on off on on off off
Defining PORTx as Input DDRx Register 0x00 0 0 0 0 0 0 0 0 vcc PORTx Register 0 1 1 0 1 1 0 0 0x6C Controls PORTx in in in in in in in in Pull-up for input
Read PORTx DDRx Register 0 0 0 0 0 0 0 0 0x00 vcc PORTx Register 1 1 1 1 1 1 1 1 0xFF Controls PORTx in in in in in in in in PINx Register 0 1 1 0 1 1 0 0 0x6C Reads Reads - + + - + + - -
PORTx Configuration on a stamp board PORTE PORTG PORTB PORTF PORTD PORTA PORTC
Digital input • PORT setting for input/output • Can be configured individually • Ex) PORTA = 0x00 // pins in PORTA are inputs PORTA = 0xFF // pins in PORTA are outputs PORTA = 0X0F // 0~3 pins are outputs // 4 ~7 pins are inputs PORTA = 0x08 // only pin3 is a output • Read PORT value (8bit) : 0 ~ 255
Digital input PIN1,2 are high(on) PIN 0,4 are low(off) Pull-up for input PIN 0 ~ 3 : Output (LED), PIN 4 ~ 7 : Input (Button) DDRA: 0x0F in in in in out outoutout PORTA: 0xF6 1 1 1 1 0 1 1 0 6 7 5 4 3 2 1 0 0 0 1 1 0 1 1 0 PINA : 0x36 (48) - + + - - + + - Button2 Button4 LED4 LED2 Button3 Button1 LED2 LED1 GND Button 1,2 : Released, Button 3, 4 : Pressed LED 1,4 : OFF , LED 3,4 : ON
Bit operations • AND ( & ) : 0 & 0 0 0 & 1 0 1 & 0 0 1 & 1 1 • OR ( | ) : 0 | 0 0 0 | 1 1 1 | 0 1 1 | 1 1 • XOR (^) : 0 ^ 0 0 0 ^ 1 1 1 ^ 0 1 1 ^ 1 0 • Bit Shifts(<< or >> ) : 1 << 3 00001000 (=8) • 40 >> 1 00101000 >> 1 00010100 (=20) 40 >> 5 00000001 (=1)
How to read only specific PIN on PORT • Ex) bitwise operations Let’s assume that we add 4 buttons on PINA4 ~ 7 and 4 LEDs on PINA0~3 LED0 PIN0, LED1 1, LED2 2, LED3 3 button0 PIN4, button1 PIN5, button2 PIN6, button3 PIN7 DDRA = 0x0F (0b00001111) : PINA0 ~3= output, PIN4~7 = input PORTA = 0xF0 (0b11110000) : pull up from PIN4 to 7 for input PINA = 0xF0 (0b11110000): initial status of PINA All LEDs are off, all buttons are released If LED2 is only need to be on PORTA = PORTA | 0x04 ( 0b00000100 ) PINA == 0xF4 ( 0b11110100 ) Then, if only button2 is need to be read PINA & 0x04 ( 0b01000000 ) Button2 released: PINA ( 0b11110100 ) & 0x40 ( 0b01000000 ) 0x40 (0b01000000)
Let’s make a simple button program • /home/csc2700/csc27000/08-button-led-3x3-01
Make a simple LED increment program • Make two buttons, a plus button and a minus button • Whenever the plus button is pushed, a number of LEDs turned on are increased all LEDs are on • Whenever the minus button is pushed, a number of LEDs turned on are decreased until all LEDs are off
Homework-4 • Create an animation player which has two buttons, a play button and a selection button • Selection button is for selecting different LED animations ( at least three LED animations ) • Play button is for controlling stop/play selected LED animations