Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Practical embedded system programming.doc
Скачиваний:
3
Добавлен:
01.07.2025
Размер:
9 Мб
Скачать
☆

Void setup()

{

pinMode(dataPin, OUTPUT); //Configure each IO Pin

pinMode(latchPin, OUTPUT);

pinMode(clockPin, OUTPUT);

}

void loop()

{

for (byte2 = 0; byte2 < 256; byte2++) //Outer Loop

{

for (byte1 = 0; byte1 < 256; byte1++) //Inner Loop

{

digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data

shiftOut(dataPin, clockPin, MSBFIRST, byte1); //Send the data byte 1

shiftOut(dataPin, clockPin, MSBFIRST, byte2); //Send the data byte 2

digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data

delay(250);

}

}

}

Example 4 - Dual Shift Register - KITT is back!

Just like the TV program, KITT made a re-appearance, but the new version had a dual sweep light on the front of the car. To achieve this, we need two arrays to store the left and right (Byte 1 + 2) values, and again an additional line to write out the second byte.

int dataPin = 2; //Define which pins will be used for the Shift Register control

int latchPin = 3;

int clockPin = 4;

int seq1[14] = {1,2,4,8,16,32,64,128,64,32,16,8,4,2}; //The array for storing the

// byte #1 value

int seq2[14] = {128,64,32,16,8,4,2,1,2,4,8,16,32,64}; //The array for storing the

// byte #2 value

Void setup()

{

pinMode(dataPin, OUTPUT); //Configure each IO Pin

pinMode(latchPin, OUTPUT);

pinMode(clockPin, OUTPUT);

}

void loop()

{

for (int x = 0; x < 14; x++) //Array Index

{

digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data

shiftOut(dataPin, clockPin, MSBFIRST, seq1[x]); //Send the data byte 1

shiftOut(dataPin, clockPin, MSBFIRST, seq2[x]); //Send the data byte 2

digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data

delay(75);

}

}

By digital signals, winking by the light-emitting diodes on the six pins. Including six green light-emitting diodes and four red light-emitting diodes.

/*

In this firmware can be activated address bus A0, A1, A2, A3, SDA and SCL

All address bus A0-A3 have receive the signals

All two wire interface i2c SDA and SCL have send the signals

This firmware operates with microcontrollers ATMEGA328P

A firmware can be debugged on the ARDUINO UNO R3

*/

//It includes a protocol into input/output of AVR

#include<avr/io.h>

//It includes a protocol into wired devices

#include<Wire.h>

Void setup() {

// put your setup code here, to run once:

//It initializes functions of the pin modes through the protocol of wire

pinMode(A0, OUTPUT); //

pinMode(A1, OUTPUT); //

pinMode(A2, OUTPUT); //

pinMode(A3, OUTPUT); //

pinMode(SDA, OUTPUT); //

pinMode(SCL, OUTPUT); //

//It initializes functions of the digital writes from main device to peripheral devices

digitalWrite(A0, HIGH); //

delay(50);

digitalWrite(A0, LOW); //

delay(50);

digitalWrite(A1, HIGH); //

delay(50);

digitalWrite(A1, LOW); //

delay(50);

digitalWrite(A2, HIGH); //

delay(50);

digitalWrite(A2, LOW); //

delay(50);

digitalWrite(A3, HIGH); //

delay(50);

digitalWrite(A3, LOW); //

delay(50);

digitalWrite(SDA, HIGH); //

digitalWrite(SCL, HIGH); //

}

void loop() {

// After creating a setup() function, which initializes and sets the initial values, the loop() function does precisely what its name suggests, and loops consecutively, allowing your program to change and respond. Use it to actively control the Arduino board.

}

//It is tested on Arduino IDE 1.0.5

#include <LiquidCrystal.h> // adding library of liquid crystal display

LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // (RS, E, DB4, DB5, DB6, DB7)

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]