- •Practical embedded system programming
- •Void setup() {
- •In this firmware can be activated address bus a0, a1, a2 and a3
- •Void setup() {
- •Void setup() {
- •Void setup()
- •Void setup()
- •Void setup()
- •Void setup()
- •Void setup()
- •Void setup() {
- •Void setup(){
- •Void setup(){
- •Void setup()
- •Void setup()
- •Void setup()
- •Void setup()
- •Void setup()
- •Void setup() {
- •Void setup() {
- •Void setup(){
- •Void setup() {
- •Void setup() {
- •Void setup()
- •Void setup()
- •Void setup() {
- •Void setup() {
- •Void setup() {
- •Void setup() {
- •Void setup()
- •Void setup()
- •Void setup()
- •Void setup() {
- •Void setup() {
- •Void setup() {
- •Void setup() {
- •Void setup() {
- •Void setup() {
Void setup()
{
pinMode(Relay, OUTPUT);
}
void loop()
{
digitalWrite(Relay, LOW); // реле включено
delay(2000);
digitalWrite(Relay, HIGH); // реле выключено
delay(2000);
}
Button:
Pushbuttons or switches connect two points in a circuit when you press them. This example turns on the built-in LED on pin 13 when you press the button.
Hardware
Arduino or Genuino Board
Momentary button or Switch
10K ohm resistor
hook-up wires
breadboard
Circuit
/*
Button
Turns on and off a light emitting diode(LED) connected to digital
pin 13, when pressing a pushbutton attached to pin 2.
The circuit:
* LED attached from pin 13 to ground
* pushbutton attached to pin 2 from +5V
* 10K resistor attached to pin 2 from ground
* Note: on most Arduinos there is already an LED on the board
attached to pin 13.
created 2005
by DojoDave <http://www.0j0.org>
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Button
*/
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
Void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
#include <avr/io.h>
int main()
{
//high nibble for output(columns) low for input(rows);
DDRB=0xF0;
//enable internal pullups for PB0-PB3
PORTB=0x0F;
//Port D for indication only
DDRD=0xFF;
while (1) //loop key check forever
{
//first column
PORTB =0b01111111;
//check for rows and send key number to portD
//instead sending key number to PORTD you can use
// any function that serves pressed button
if (bit_is_set(PINB, 3)) PORTD=1;
if (bit_is_set(PINB, 2)) PORTD=2;
if (bit_is_set(PINB, 1)) PORTD=3;
if (bit_is_set(PINB, 0)) PORTD=4;
//second column
PORTB =0b10111111;
if (bit_is_set(PINB, 3)) PORTD=5;
if (bit_is_set(PINB, 2)) PORTD=6;
if (bit_is_set(PINB, 1)) PORTD=7;
if (bit_is_set(PINB, 0)) PORTD=8;
//third column
PORTB =0b11011111;
if (bit_is_set(PINB, 3)) PORTD=9;
if (bit_is_set(PINB, 2)) PORTD=10;
if (bit_is_set(PINB, 1)) PORTD=11;
if (bit_is_set(PINB, 0)) PORTD=12;
//fourth column
PORTB =0b11101111;
if (bit_is_set(PINB, 3)) PORTD=13;
if (bit_is_set(PINB, 2)) PORTD=14;
if (bit_is_set(PINB, 1)) PORTD=15;
if (bit_is_set(PINB, 0)) PORTD=16;
}
}
/*
LiquidCrystal Library - Autoscroll
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
library works with all LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.
This sketch demonstrates the use of the autoscroll()
and noAutoscroll() functions to make new text scroll or not.
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
Library originally added 18 Apr 2008
by David A. Mellis
library modified 5 Jul 2009
by Limor Fried (http://www.ladyada.net)
example added 9 Jul 2009
by Tom Igoe
modified 22 Nov 2010
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/LiquidCrystalAutoscroll
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
