-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sketch_of_SPI_Arduino_communication.ino
59 lines (59 loc) · 1.13 KB
/
Sketch_of_SPI_Arduino_communication.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <SPI.h> // necessary library
int ss=10; // using digital pin 10 for SPI slave select
int del=15; // used for fading delay
void setup()
{
pinMode(ss, OUTPUT); // we use this for SS pin
SPI.begin(); // wake up the SPI bus.
SPI.setBitOrder(MSBFIRST);
// our AD5204 requires data to be sent MSB (Most Significant Bit) first. See data sheet
allOff(); // we do this as pot memories are volatile
}
void allOff()
// sets all potentiometers to minimum value
{
for (int z=0; z<4; z++)
{
setPot(z,0);
}
}
void allOn()
// sets all potentiometers to maximum value
{
for (int z=0; z<4; z++)
{
setPot(z,255);
}
}
void setPot(int pot, int level)
// sets potentiometer 'pot' to level 'level'
{
digitalWrite(ss, LOW);
SPI.transfer(pot);
SPI.transfer(level);
digitalWrite(ss, HIGH);
}
void blinkAll(int count) {
for (int i=0;i<count;i++) {
for (int z=0; z<4; z++) {
setPot(z,255);
delay(500);
setPot(z,0);
delay(500); }}}
void Infad() {
for (int a=0; a<4; a++) {
for (int l=0; l<255; l++) {
setPot(a,l);
delay(del); }
for (int l=255; l>=0; --l) {
setPot(a,l);
delay(del); }}}
void loop() {
blinkAll(3);
allOn();
delay(1000);
Infad();
delay(5000);
allOff();
delay(1000);
}