论坛上小伙伴已经点亮之,看了一下,有些迷糊。
http://www.52pi.net/forum.php?mod=viewthread&tid=1382
不过咱有咱的笨方法:
首先找到哪个IO控制小灯
-
#include <stdio.h>
-
#include <wiringPi.h>
-
#include <mcp23017.h>
-
-
#define EXTEND_BASE 100
-
-
int main (void)
-
{
-
wiringPiSetup( );
-
mcp23017Setup( EXTEND_BASE, 0x20 );
-
-
int i;
-
for ( i = 0 ; i < 16 ; i++ )
-
{
-
pinMode( EXTEND_BASE + i, OUTPUT );
-
}
-
-
for (;;)
-
{
-
for( i = 0 ; i < 16; i++)
-
{
-
printf("%d\n", i);
-
digitalWrite ( EXTEND_BASE + i, HIGH);
-
delay (1000);
-
digitalWrite ( EXTEND_BASE + i, LOW);
-
delay (1000);
-
}
-
}
-
return 0 ;
-
}
-
通过观察,得出对应关系如下:
13 绿
14 红
15 蓝
然后,控制点灯是不是就很简单了?
下边一个简单的代码,同时控制RGB亮灭来调色(算黑色熄灭在内,8色)
-
#include <stdio.h>
-
#include <wiringPi.h>
-
#include <mcp23017.h>
-
-
-
#define EXTEND_BASE 100
-
-
int main (void)
-
{
-
-
wiringPiSetup( );
-
mcp23017Setup( EXTEND_BASE, 0x20 );
-
-
int i;
-
for ( i = 0 ; i < 16 ; i++ )
-
{
-
pinMode( EXTEND_BASE + i, OUTPUT );
-
}
-
-
for (;;)
-
{
-
for( i = 0 ; i < 8; i++)
-
{
-
-
if(i&0b00000001)
-
digitalWrite ( EXTEND_BASE + 15, HIGH);
-
if(i&0b00000010)
-
digitalWrite ( EXTEND_BASE + 13, HIGH);
-
if(i&0b00000100)
-
digitalWrite ( EXTEND_BASE + 14, HIGH);
-
-
delay(2000);
-
digitalWrite ( EXTEND_BASE + 13, LOW);
-
digitalWrite ( EXTEND_BASE + 14, LOW);
-
digitalWrite ( EXTEND_BASE + 15, LOW);
-
-
}
-
}
-
}
-
好了,小灯会依次按如下顺序闪亮:
黑(灭),蓝,绿,青,红,粉,黄,白
顺便提醒一句,亮瞎双眼啊。
我这篇文章全是盲打的。