forked from ric96/libsx1509
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsx1509.cpp
79 lines (72 loc) · 1.25 KB
/
sx1509.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* Title: SX1509 GPIO expander interfacing with 96Boards CE
* Author: Sahaj Sarup
* Copyright (c) 2017 Linaro Inc.
* All rights reserved.
*
*/
#include "sx1509.h"
#include <time.h>
#include <stdio.h>
#include <signal.h>
int running = 0;
void
sig_handler(int signo)
{
if (signo == SIGINT)
{
printf("closing IO nicely\n");
running = -1;
}
}
int main()
{
SX1509 a;
a.init(0x3e, 0);
SX1509 b;
//b.init(0x3f, 0);
signal(SIGINT, sig_handler);
for(uint8_t i = 0; i<=3 && running==0; i++)
{
a.pinMode(i, OUTPUT);
a.digitalWrite(i,LOW);
}
a.pinMode(8,INPUT_PULLUP);
for(uint8_t i = 0; i<=3 && running==0; i++)
{
a.digitalWrite(i, HIGH);
sleep(1);
a.digitalWrite(i,LOW);
}
for(uint8_t i = 0; i<=3 && running==0; i++)
a.pinMode(i, ANALOG_OUTPUT);
uint8_t i=0;
while(1>0 && running==0)
{
printf("%u\n",a.digitalRead(8));
uint8_t k = 255;
while(a.digitalRead(8)==1 && k>=0 && running==0)
{
if(k==0)
{
k=255;
a.analogWrite(i,k);
i++;
if(i>3)
i=0;
}
a.analogWrite(i,k);
k--;
nanosleep((const struct timespec[]){{0, 20000000L}}, NULL);
}
if(k!=255)
{
a.analogWrite(i,255);
i++;
if(i>3)
i=0;
}
nanosleep((const struct timespec[]){{0, 20000000L}}, NULL);
}
a.reset();
}