void SenseMeLEDMatrixClass::begin(void) {
  i2c_addr = 0x70;

  Wire.begin();

  Wire.beginTransmission(i2c_addr);
  Wire.write(0x21);  // turn on oscillator
  Wire.endTransmission();
  blinkRate(HT16K33_BLINK_OFF);
  
  setBrightness(15); // max brightness
}
예제 #2
0
파일: Sensor.cpp 프로젝트: markkampe/Alarm
/**
 * run through each of the four color phases 
 * (red, off, green off) for all of the LEDs, 
 * based on the color state for each sensor.
 *
 * Assertion: 
 *	at entry, all LED output shift states are zero
 *	because that is how we initialize them, 
 *	and that is how we leave them from here.
 */
void SensorManager::update() {

	long now = millis();	// time for blink management
	
	// turn on any red LEDs that need to be turned on
	int set = 0;
	for( int i = 0; i < cfg->sensors->num_sensors; i++ ) {
	    // if the sensor isn't configured ignore it

	    // see if we are blinked off
	    int b = blinkRate(i);
	    if (b > 0 && ((now/b) & 1))
		continue;

	    // see if we should turn this red LED on
	    if (hasRed(i)) {
		outshifter->set(cfg->sensors->red(i), true);
		set++;
	    }
	}
	outshifter->write();	// and latch those values
	delayMicroseconds(cfg->leds->usRed());

	// turn off all the red LEDs
	if (set > 0) {
	    for( int i = 0; i < cfg->sensors->num_sensors; i++ ) {
		    outshifter->set(cfg->sensors->red(i), 0);
	    }
	    outshifter->write();	// and latch those values
	}
        if (cfg->leds->usOff() > 1)
		delayMicroseconds(cfg->leds->usOff()/2);
		
	// turn on any green LEDs that need to be turned on
	set = 0;
	for( int i = 0; i < cfg->sensors->num_sensors; i++ ) {
	    // see if we are blinked off
	    int b = blinkRate(i);
	    if (b > 0 && ((now/b) & 1))
		continue;

	    // see if we should turn this green LED on
	    if (hasGreen(i)) {
		outshifter->set(cfg->sensors->green(i), true);
		set++;
	    }
	}
	outshifter->write();	// and latch those values
	delayMicroseconds(cfg->leds->usGreen());

	// turn off all the greens
	if (set > 0) {
	    for( int i = 0; i < cfg->sensors->num_sensors; i++ ) {
	        outshifter->set(cfg->sensors->green(i), 0);
	    }
	    outshifter->write();	// and latch those values
	}

        if (cfg->leds->usOff() > 0)
		delayMicroseconds((1+cfg->leds->usOff())/2);

#ifdef DEFIB
	unsigned s = now/1000;		// current (second) time
	if (nextUpdate > s + cfg->controls->minInterval())
		nextUpdate = s;		// correct for time wrap
#endif
	// zone updates
	for( int i = 1; i <= cfg->sensors->numZones(); i++ ) {
		// flush out the state of each trigger relay
		int p = cfg->sensors->zonePin(i);
		if (p > 0) {
			int t = zoneState & (1 << i);
			digitalWrite(p, t ? HIGH : LOW);
		}
#ifdef DEFIB
		// decrement defib counters at max allowable rate
		if (s >= nextUpdate) {
			if (defib[i] > 0)
				defib[i]--;
		}
#endif
	}

#ifdef DEFIB
	// schedule the next counter update
	if (s >= nextUpdate)
		nextUpdate = s + cfg->controls->minInterval();
#endif
}