/*
* piGlow.c:
* Easy access to the Pimoroni PiGlow board.
*
* Copyright (c) 2013 Gordon Henderson.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see .
***********************************************************************
*/
#include
#include
#include "piGlow.h"
static int myBase ;
static int leg0 [6] = { 6, 7, 8, 5, 4, 9 } ;
static int leg1 [6] = { 17, 16, 15, 13, 11, 10 } ;
static int leg2 [6] = { 0, 1, 2, 3, 14, 12 } ;
/*
* piGlow1:
* Light up an individual LED
*********************************************************************************
*/
void piGlow1 (const int leg, const int ring, const int intensity)
{
int *legLeds ;
if ((leg < 0) || (leg > 2)) return ;
if ((ring < 0) || (ring > 5)) return ;
/**/ if (leg == 0)
legLeds = leg0 ;
else if (leg == 1)
legLeds = leg1 ;
else
legLeds = leg2 ;
analogWrite (myBase + legLeds [ring], intensity) ;
}
/*
* piGlowLeg:
* Light up all 6 LEDs on a leg
*********************************************************************************
*/
void piGlowLeg (const int leg, const int intensity)
{
int i ;
int *legLeds ;
if ((leg < 0) || (leg > 2))
return ;
/**/ if (leg == 0)
legLeds = leg0 ;
else if (leg == 1)
legLeds = leg1 ;
else
legLeds = leg2 ;
for (i = 0 ; i < 6 ; ++i)
analogWrite (myBase + legLeds [i], intensity) ;
}
/*
* piGlowRing:
* Light up 3 LEDs in a ring. Ring 0 is the outermost, 5 the innermost
*********************************************************************************
*/
void piGlowRing (const int ring, const int intensity)
{
if ((ring < 0) || (ring > 5))
return ;
analogWrite (myBase + leg0 [ring], intensity) ;
analogWrite (myBase + leg1 [ring], intensity) ;
analogWrite (myBase + leg2 [ring], intensity) ;
}
/*
* piGlowSetup:
* Initialise the board & remember the pins we're using
*********************************************************************************
*/
void piGlowSetup (const int pinBase)
{
sn3218Setup (myBase = pinBase) ;
// Turn all off to start with
piGlowLeg (0, 0) ;
piGlowLeg (1, 0) ;
piGlowLeg (2, 0) ;
}