Example #1
0
void IOToaster::setup()
{
	// Set the pin configuration
	setupPins();

	// Open serial communication
	Serial.begin(9600);
	Serial.setTimeout(5000);	

	// Load the configuration
	if (isConfigured())
	{
		// Normal mode
		_setupMode = false;
		loadConfiguration();	
		connectServer();
		setActivityLedState(HIGH);		
	}
		
	else {
		// Setup mode
		setActivityLedState(LOW);
		_setupMode = true;		
		createServer();
	}
}
Example #2
0
Radioino::Radioino(byte inputPins[], byte outputPins[], byte analogInputPins[])
{
	_activityLedPin = RADIOINO_ACTIVIY_LED_PIN;
	_setupButtonPin = RADIOINO_SETUP_BUTTON_PIN;
	_setupMode = false;	
	_activityLedState = false;	

	// Load module address
	loadAddress();
	
	_inputPinsCount = inputPins[0];
	_outputPinsCount = outputPins[0];
	_analogInputPinsCount = analogInputPins[0];
	
	_inputPins = inputPins+sizeof(byte);
	
	// Setup output pins state array
	_outputPins = new PinState[_outputPinsCount];
	for (int i=0; i<_outputPinsCount;i++)
	{
		_outputPins[i].number = outputPins[i+1]; // The first by is the count
	}
	
	_analogInputPins = analogInputPins+sizeof(byte);
	
	
  // Alloc strings
  _command.reserve(50);
  _response.reserve(255);
  _value.reserve(3);

  // Set the pin configuration
  setupPins();
}
Example #3
0
int main() {
	wiringPiSetup();
	printf("Light Beat Channels: %d\n",grpAllCount);
	setupPins();

	pthread_t tid;
	pthread_create(&tid,NULL,beat,NULL);

	int i;
	int loops = 5;
	for (i=1;i<=loops;i++)
	{
		printf("Loop %d/%d\n",i,loops);
		//allLights(HIGH);
		//delay(1000);
		//allLights(LOW);
		delay(1000);
		//kitt();
		//groupLights(grp1,grp1Count,HIGH);
		//delay(500);
		groupLights(grp3,grp3Count,ON);
		delay(1000);
		groupLights(grp3,grp1Count,OFF);
		groupLights(grp2,grp2Count,ON);
		delay(1000);
		groupLights(grp2,grp2Count,OFF);
	}
	//pthread_exit(NULL);

	allLights(OFF);
	return 0;
}
SevenSeg::SevenSeg(Device::pin_t const segmentPins[], bool hasDecimalPoint, connector_t connector)
    :	_hasDecimalPoint(hasDecimalPoint)
{
    setupPins(segmentPins);
    setupSignals(connector);

    clear();
}
void loop()
{

  if(serialStatus==0)
  {
    Serial.flush();
    setupPins();
  }
  askCmd();

  {
    if(Serial.available()>0)
    {
      cmd = int(Serial.read()) - 48;
  
      if(cmd==0) //set digital low
      {
        cmd_arg[0] = int(readData()) - 48;
        digitalWrite(cmd_arg[0],LOW);
      }
  
      if(cmd==1) //set digital high
      {
        cmd_arg[0] = int(readData()) - 48;
        digitalWrite(cmd_arg[0],HIGH);
      }
  
      if(cmd==2) //get digital value
      {
        cmd_arg[0] = int(readData()) - 48;
        cmd_arg[0] = digitalRead(cmd_arg[0]);
        Serial.println(cmd_arg[0]);
      }
  
      if(cmd==3) // set analog value
      {
        Serial.println("I'm in the right place");
        cmd_arg[0] = int(readData()) - 48;
        cmd_arg[1] = readHexValue();
        analogWrite(cmd_arg[0],cmd_arg[1]);
      }
  
      if(cmd==4) //read analog value
      {
        cmd_arg[0] = int(readData()) - 48;
        cmd_arg[0] = analogRead(cmd_arg[0]);
        Serial.println(cmd_arg[0]);
      }
  
      if(cmd==5)
      {
        serialStatus = 0;
      }
    }
  }
}
Example #6
0
//Takes a pin number for each channel bit. Also takes a specific 
//signal pin number.
Multiplexer::Multiplexer(int bit_0_pin, int bit_1_pin, int bit_2_pin, int bit_3_pin, int signal_pin)
{
	this->channel_pins[0] = bit_0_pin;
	this->channel_pins[1] = bit_1_pin;
	this->channel_pins[2] = bit_2_pin;
	this->channel_pins[3] = bit_3_pin;
	this->channel_pins[4] = signal_pin;
	
	setupPins();
}
Example #7
0
//Takes only the pin number of the lowest channel bit and assumes
//that the next three pins are the next three bits. Also takes a specific
//signal pin number.
Multiplexer::Multiplexer(int low_pin, int signal_pin)
{
	for (int i = low_pin; i < low_pin + 4; i++)
	{
		this->channel_pins[i - low_pin] = i;
	}
	this->channel_pins[4] = signal_pin;
	
	setupPins();
}
Example #8
0
TankDrive::TankDrive ()
{
	_speedPinLeft = 10;
	_speedPinRight= 5;
	_forwardPinLeft = 9;
	_reversePinLeft = 8;
	_forwardPinRight = 7;
	_reversePinRight = 6;
	
	setupPins();
}
Example #9
0
TankDrive::TankDrive(int speedPinLeft, int speedPinRight, int forwardPinRight, int reversePinRight, int forwardPinLeft, int reversePinLeft):_trapezoid()
{
	// connect motor controller pins to Arduino digital pins
	// motor Left
	_speedPinLeft = speedPinLeft;
	_forwardPinLeft = forwardPinLeft;
	_reversePinLeft = reversePinLeft;
	// motor two
	_speedPinRight = speedPinRight;
	_forwardPinRight = forwardPinRight;
	_reversePinRight = reversePinRight;

	setupPins();
}
Example #10
0
Multiplexer::Multiplexer(int bit_0_pin, int bit_1_pin, int bit_2_pin, int bit_3_pin, int signal_pin, int settings[])
{
	this->channel_pins[0] = bit_0_pin;
	this->channel_pins[1] = bit_1_pin;
	this->channel_pins[2] = bit_2_pin;
	this->channel_pins[3] = bit_3_pin;
	this->channel_pins[4] = signal_pin;
	
	for (int i = 0; i < 16; i++)
	{
		_muxPinSettings[i] = settings[i];
	}
	
	setupPins();
}
Ecolino_Hijacker::Ecolino_Hijacker()
{
   setupPins();

   refresh_states();
   
   for (int i = 0; i < num_ecolino_buttons; i++)
      hijacked_button_states[i] = BUTTON_ACTION_PASSTHROUGH;
	  
   for (int i = 0; i < num_ecolino_leds; i++)
      hijacked_led_states[i]    = LED_ACTION_PASSTHROUGH;
	  
   force_hijack_update(); // shift out the appropriate states from the panel to the board
	  
	  
      
}
Example #12
0
alphaNumericLCD::alphaNumericLCD(s_DataPins pins)
{
	if(!mInitialized)
	{
		mInitialized = true;

		mPins = pins;

		powerPorts(mPins);
		setupPins(mPins);


		CYGHWR_HAL_STM32_GPIO_OUT (pins.rsPin, 0);
		CYGHWR_HAL_STM32_GPIO_OUT (pins.rwPin, 0);
		CYGHWR_HAL_STM32_GPIO_OUT (pins.ePin, 1);

		initLCM();

	}
}
Example #13
0
void SmSnDevice::setup() {
    setupPins();

    setColor(RGB_YELLOW);

    //morse = createMorse();

/*
    droidspeak = createDroidspeak();
    if (droidspeak) {
        droidspeak->speakPowerUpPhrase();
    }
*/

    osc.beginSerial();

    bundleIn = new OSCBundle();

    setupOther();

    // delay the serial open phrase until the random number generator has been seeded
    setColor(RGB_GREEN);
    /*
    if (droidspeak) {
        droidspeak->speakSerialOpenPhrase();
    }
    */
    setColor(RGB_BLACK);

    vibrate(500);
    osc.sendInfo("%s is ready", osc.getPrefix());

    loopCount = 0;
    loopThreshold = 100;
    // initial value for loop time gets us through the first half second or so
    loopTime = 4.0/1000;
    loopStartTime = millis();
}
Example #14
0
int main() {
	// Make sure our watchdog timer is disabled!
	wdt_reset();
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	// set for 16 MHz clock
	CPU_PRESCALE(0);

	// Initialize the USB, and then wait for the host to set configuration.
	// If the board is powered without a PC connected to the USB port,
	// this will wait forever.
	usb_init();
	while (!usb_configured()) /* wait */ ;

	// Wait an extra second for the PC's operating system to load drivers
	// and do whatever it does to actually be ready for input
	_delay_ms(1000);

	setupPins();
	
	// main loop
	loop();
}
Example #15
0
void loop()
{
  // TLed;
  // _delay_ms(300);
  // dbg_c(ENC_LinkSt?'~':'_');
  if (ENC_LinkSt)
  {
    if (ENC_hasRxd)
    {
      packet_length = ENC_PckRx(_rx_buffer, BUFFER_SIZE);
      if (packet_length > 0)
      {
        // Return 1 if packet was ARP, and was handeld
        if (!ifARP_Reply(_rx_buffer, packet_length))
        {
          // Return IPHLen if valid IP Packet, else 0
          ip_header_length = IP_Check(_rx_buffer, packet_length);
          if (ip_header_length > 0)
          {
            protocol_type = IP_gProtocol(_rx_buffer);
            if (protocol_type == IP_pICMP)
            {
              // dbg_s("ICMP\n");
              ICMP_Reply(_rx_buffer, ip_header_length, packet_length);
            }
            else if (protocol_type == IP_pUDP)
            {
             // Serial.println("Got UDP package");
              // dbg_s("UDP\n");
              _rx_buffer_length = UDP_Recv(_rx_buffer, ip_header_length, packet_length);
              if (_rx_buffer_length > 0)
              {
                buffer_ptr = _rx_buffer + IP_Start + ip_header_length + UDP_HeaderLen;

                if (isSetupData(buffer_ptr))
                {
                  // parse setup data and setup teensy
                  parseSetupData(buffer_ptr);
                  if (!is_setup)
                    setupPins(&_setup_data);
                  UDP_Send(_rx_buffer, ip_header_length, _rx_buffer_length, ModeReply);
                  is_setup = 1;
                }
                else if (is_setup && isLightData(buffer_ptr))
                {
                  // quickly store received light data to immediately send out sensor data
                  memcpy(light_buffer, buffer_ptr, sizeof(light_buffer));
                  // get sensor data and send it out
                  for (uint8_t i = 0; i < _setup_data.num_sensors; ++i)
                  {
                    if (digitalRead(_setup_data.sensors[i].pin))
                    {
                      _sensor_data.sensor_value[i] = (uint8_t)0;
                    }
                    else
                    {
                      _sensor_data.sensor_value[i] = (uint8_t)1;
                    }
                  }
                  generateSensorData(buffer_ptr, &_sensor_data);
                  UDP_Send(_rx_buffer, ip_header_length, _rx_buffer_length, ModeReply);

                  // overwrite the rx_buffer again and parse light data and set it
                  memcpy(buffer_ptr, light_buffer, sizeof(light_buffer));
                  parseLightData(buffer_ptr);

                  for (uint8_t i = 0; i < _setup_data.num_block_leds; ++i)
                  {
                    uint8_t pin = _setup_data.block_leds[i].pin;
                    uint8_t index = _setup_data.block_leds[i].index;
                    uint8_t num = index + _setup_data.block_leds[i].num_blocks;
                    for (uint8_t j = index; j < num; ++j)
                    {
                      light_strips[pin].setPixelColor((uint16_t)j,
                                                      _light_data.block_leds[i].red,
                                                      _light_data.block_leds[i].green,
                                                      _light_data.block_leds[i].blue);
                    }
                  }

                  for (uint8_t i = 0; i < _setup_data.num_pixel_leds; ++i)
                  {
                    uint8_t pin = _setup_data.pixel_leds[i].pin;
                    uint8_t index = _setup_data.pixel_leds[i].index;
                    uint8_t num = index + _setup_data.pixel_leds[i].num_pixels;
                    for (uint8_t j = index; j < num; ++j)
                    {
                      light_strips[pin].setPixelColor((uint16_t)j,
                                                      _light_data.pixel_leds[i].red[j],
                                                      _light_data.pixel_leds[i].green[j],
                                                      _light_data.pixel_leds[i].blue[j]);
                    }
                  }

                  // let there be light
                  for (uint8_t i = 0; i < _setup_data.num_strips_used; ++i)
                  {
                    light_strips[i].show();
                  }
                }
              }
            } // IP Packet Type
          } // else dbg_s("\nUnhandeld IP Packet.");
        } // else dbg_s("\nARP"); // IP or ARP //d bg_c('\n');
      } //  GotEth Packet
    } // Packet Available
  } // Link is Up

}
Example #16
0
void setup() {
  // connect to the serial port
  Serial.begin(115200);
  setupPins();
  serialStatus = 1;
}
void CRC_Hardware::init() {
	seedRandomGenerator();
	setupPins();
	setupSPI();
	setupI2C();
}