Example #1
0
boolean OV7670::begin(void) {

	// setup parrallel interface.
//	pinmode(_WEN, OUTPUT); // WEN
	pinlow(_WEN);
	pinmode(_VSYNC, INPUT);  // VSYNC

	pinmode(_HREF, INPUT);  // HREF
	pinmode(_RRST, OUTPUT);
	pinhigh(_RRST);

	// RCLK 1MHz  by TC2 fast-PWM with TOP=OCRA
	pinmode(_RCLK, OUTPUT);
	pinhigh(_RCLK);

	pinmode(_OE, OUTPUT);
	pinhigh(_OE);

#ifdef DEBUG
	Serial.println(_HREF, HEX);
	Serial.println(_RRST, HEX);
	Serial.println("Ok?");
	while(1);
#endif

	Serial.println("pin modes have been set.");

	resetRegisters(); // reset all registers
	Serial.println("registers reseted.");

	return writeRegisterValues(REGCONF_QVGA_RGB565)
			&& writeRegisterValues(REGCONF_COLOR_SETTING);

}
void LedControl_init(u8 dataPin, u8 clkPin, u8 csPin, u8 numDevices)
{
    u8 i;
    
    LEDCONTROL_SPI_MOSI = dataPin;
    LEDCONTROL_SPI_CLK  = clkPin;
    LEDCONTROL_SPI_CS   = csPin;
    if(numDevices<=0 || numDevices>8 )
        numDevices=8;
    maxDevices=numDevices;
    pinmode(LEDCONTROL_SPI_MOSI,OUTPUT);
    pinmode(LEDCONTROL_SPI_CLK,OUTPUT);
    pinmode(LEDCONTROL_SPI_CS,OUTPUT);
    digitalwrite(LEDCONTROL_SPI_CS,HIGH);
    LEDCONTROL_SPI_MOSI=dataPin;
    for(i=0;i<64;i++) 
        status[i]=0x00;
    for(i=0;i<maxDevices;i++)
    {
        LedControl_spiTransfer(i,OP_DISPLAYTEST,0);
        //scanlimit is set to max on startup
        LedControl_setScanLimit(i,7);
        //decode is done in source
        LedControl_spiTransfer(i,OP_DECODEMODE,0);
        LedControl_clearDisplay(i);
        //we go into shutdown-mode on startup
        LedControl_shutdown(i,true);
    }
}
Example #3
0
void setup() {
//
	pinmode(D,INPUT);
	pinmode(I,INPUT);
	ServoAttach(RD);
	ServoAttach(RI);
	ServoAttach(LD);
	ServoAttach(LI);
}
void setup(){
//
	pinmode(HOUR, INPUT);
	pinmode(MIN, INPUT);
	
//
	pinmode(SENSOR, INPUT);
		
//
	Init(NON_INVERTED);   // initialise the library
	ClearScreenX();	
}
void touch_initTouch(unsigned char orient_tation){
    orient_t = orient_tation;

    pinmode(T_CLK,  OUTPUT);
    pinmode(T_CS,   OUTPUT);
    pinmode(T_DIN,  OUTPUT);
    pinmode(T_DOUT, INPUT);
    pinmode(T_IRQ,  INPUT);

    digitalwrite(T_CS,  HIGH);
    digitalwrite(T_CLK, HIGH);
    digitalwrite(T_DIN, HIGH);
    digitalwrite(T_CLK, HIGH);
}
Example #6
0
//private function
void Keypad_initializePins(){

	unsigned char c,r;

	for (r=0; r<keypad_rows; r++){
        for (c=0; c<keypad_columns; c++){
			pinmode(columnPins[c],OUTPUT);
			digitalwrite(columnPins[c],HIGH);
        }
		//configure row pin modes and states
		pinmode(rowPins[r],INPUT);
		digitalwrite(rowPins[r],HIGH);
    }
}
Example #7
0
/* Configuración de pines de entrada/salida */
void setup()
{
    TRISB=0; //defino PORTB como salida
    PORTB=0; 
    PORTD=0;
    pinmode(ICR_DIG1,INPUT);
    pinmode(ICR_DIG2,INPUT);
    /* si se activa el sensor de ultra sonido, funciona como salida*/
    pinmode(ICR_DIG3,TRIG);
    pinmode(ICR_DIG4,ECHO);
    pinmode(ICR_l293_P1,OUTPUT);
    pinmode(ICR_l293_P2,OUTPUT);
    pinmode(ICR_l293_P3,OUTPUT);
    pinmode(ICR_l293_P4,OUTPUT);
    ServoAttach(ICR_SRV1);
    ServoAttach(ICR_SRV2);
    ServoAttach(ICR_SRV3);
    ServoAttach(ICR_SRV4);
    ServoAttach(ICR_SRV5);
    #if defined(__USART__)
    serial_begin(9600);  
    Delayms(1000);
    #endif
    #if defined(__LCD__)
	//Uso el PORTB para el LCD (usando los primeros 4bits y los
	// otros dos para RS y E
	lcd(4, 5, 0, 1, 2, 3, 0, 0, 0, 0); // RS, E, D4 ~ D8	
	// Defino el numero de columnas y filas del LCD: 
    	begin(8, 2);
        home();
    #endif
}
Example #8
0
void IRrecv_enableIRIn(u8 recvpin)
{
    u32 f=GetPeripheralClock();
    
    // Configure interrupt
    IntConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
    IntSetVectorPriority(INT_TIMER3_VECTOR, 7, 3);
    IntClearFlag(INT_TIMER3);
    IntEnable(INT_TIMER3);

    // Configure Timer3 to overload every 50us
    T3CON    = 0;                       // no prescaler
    TMR3     = 0;                       // clear timer register
    PR3      = 50*(f/1000/1000);        // nb cycles / 50 us
    T3CONSET = 0x8000;                  // start timer 1

    // initialize state machine variables
    irparams.recvpin = recvpin;
    irparams.blinkflag = 0;
    irparams.rcvstate = STATE_IDLE;
    irparams.rawlen = 0;

    // set pin modes
    pinmode(irparams.recvpin, INPUT);
}
Example #9
0
void lwn_setup() {
	  // LED_Blinker setup
	  pinmode(LWN_DATA_PIN,OUTPUT);
	  pinmode(LWN_CLK_PIN, OUTPUT);
	  digitalwrite(LWN_CLK_PIN, LOW);

	  lwn_state = LWN_S_WAIT_FOR_DATA_SET;
	  lwn_sub_state = LWN_SS_WRITE_ZEROS;

	  lwn_us_delay = 0;
	  lwn_bitmask = 0x80;
	  context->zeroCounter = ZEROS_NEEDED;
	  context->pixelIndex = 0;
	  lwn_timer.timer_delay = 1;	// needs to be 1 to prevent overflow and wait forever
	  reset_us_timer(&lwn_timer, lwn_us_delay);
}
Example #10
0
void setup()
{
for (i=0;i<8;i++) 	{
				pinmode(i,OUTPUT);
				digitalwrite(i,LOW);
				}
serial_begin(9600);
}
Example #11
0
void setup() {
  int thisPin;
//
  serial1init(9600); 
//
      for (thisPin = 2; thisPin < 7; thisPin++) {
        pinmode(thisPin, OUTPUT);
      } 
}
Example #12
0
void initSD(void)
{
	digitalwrite(SDCS, HIGH);	// initially keep the SD card disabled
	pinmode(SDCS, OUTPUT);		// make Card select an output pin

	// init the spi module for a slow (safe) clock speed first
	SPI2CON = 0x8120;   // ON (0x8000), CKE=1 (0x100), CKP=0, Master mode (0x20)
	SPI2BRG = (GetPeripheralClock() / (2 * 250000)) - 1;
}   // initSD
Example #13
0
void setup()
{
    TRISB=0;
    pinmode(15,INPUT);
    pinmode(21,INPUT);
    pinmode(22,INPUT);
    pinmode(23,INPUT);
    pinmode(24,INPUT);
    pinmode(25,OUTPUT);
    pinmode(26,OUTPUT);
    pinmode(27,OUTPUT);
    pinmode(28,OUTPUT);
    ServoAttach(10);
    ServoAttach(11);
    ServoAttach(12);
    ServoAttach(8);
    ServoAttach(9);
}
Example #14
0
void SPI_init()
{
	SSPCON1bits.SSPEN = 0;

	switch(this_mode)
	{
		case SPI_MODE0:
			SSPCON1bits.CKP = 0;
			SSPSTATbits.CKE = 1;
			break;
		case SPI_MODE1:
			SSPCON1bits.CKP = 0;
			SSPSTATbits.CKE = 0;
			break;
		case SPI_MODE2:
			SSPCON1bits.CKP = 1;
			SSPSTATbits.CKE = 1;
			break;
		case SPI_MODE3:
			SSPCON1bits.CKP = 1;
			SSPSTATbits.CKE = 0;
			break;
	}

	SSPCON1 = (SSPCON1 & 0xF7) | this_mode;

	if (this_clock <= SPI_CLOCK_TIMER2)
		pinmode(SCKPIN, OUTPUT);
	else
		pinmode(SCKPIN, INPUT);
		
	pinmode(SDIPIN, INPUT);
	pinmode(SDOPIN, OUTPUT);
	if (this_role == SPI_SLAVE_SS)
		pinmode(SSPIN, INPUT);

	SSPCON1bits.SSPEN = 1;
}
Example #15
0
/** Init LCD 
 * mode 	=> 1 => 4 bits // 0 => 8 bits
 * rs , rw, enable
 * pins => D0 ~ D7.
 */
void _lcd_init(u8 fourbitmode, u8 rs, u8 rw, u8 enable, 
			u8 d0, u8 d1, u8 d2, u8 d3,
			u8 d4, u8 d5, u8 d6, u8 d7)
{
	u8 i;

	_rs_pin = rs;
	_rw_pin = rw;
	_enable_pin = enable;

	_data_pins[0] = d0;
	_data_pins[1] = d1;
	_data_pins[2] = d2;
	_data_pins[3] = d3; 
	_data_pins[4] = d4;
	_data_pins[5] = d5;
	_data_pins[6] = d6;
	_data_pins[7] = d7; 

	pinmode(_rs_pin, OUTPUT);

	pinmode(_enable_pin, OUTPUT);

	if (fourbitmode)
	{
		_displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
		for (i = 0; i < 4; i++)
			pinmode(_data_pins[i], OUTPUT);
	}
	else
	{
		_displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS;
		for (i = 0; i < 8; i++)
			pinmode(_data_pins[i], OUTPUT);
	}
}
Example #16
0
void Enriduino::start(){
  if (Serial.available()){
     serial[i++] = Serial.read();  
  }
  if (serial[i-1]==126){
    i=0;
    pinmode();
    Write();
    Read();
    AWrite();
    ARead();
    servo();
    servoWrite();
  }
}
void setup()
{
	pinmode(A0, INPUT);
	pinmode(A1, INPUT);
	pinmode(A2, INPUT);
	pinmode(A3, INPUT);
	pinmode(A4, INPUT);
	pinmode(A5, INPUT);
	pinmode(L, OUTPUT);
	pinmode(R, OUTPUT);
	int rightturn=0;
	int leftturn=0;
	int bumps=0;
	int comparetoV;
	
	float L=0;
	float R=0;
}
Example #18
0
int main () {
	printf("Raspberry Pi Blink\n");

	if (wiringPiSetup() == -1)
		return -1;

	pinmode(1, OUTPUT);

	for (;;) {
		digitalWrite(0, 1);
		delay(500);
		digitalWrite(0, 0);
		delay(500);
	}

	return 0;
}
Example #19
0
void setup(){
//
	/* Debug */	
//
		
//
//
//
	x = 0;
	y = 0;
	
	pinmode(LED, OUTPUT);
	
//
//
	Init(0);
	
//
//
//
	GotoXY(10,0);
//
//
//
//
	
//
//
	
//
//
//
//
//
//
//
}
Example #20
0
u8 analogwrite(u8 pin, u16 setpoint)
{
#if defined(PIC32_PINGUINO_220)
	switch (pin)
	{
		case 2:
			pinmode(2, OUTPUT);
			OC3CON=0;		// PWM Off
			OC3R=setpoint;	// Timer3 will be compared to this values
			OC3RS=setpoint;
			OC3CON=0x000E;
			OC3CON|=0x8000;	// PWM On
			return 1;
		case 3:
			pinmode(3, OUTPUT);
			OC4CON=0;		// PWM Off
			OC4R=setpoint;	// Timer3 will be compared to this values
			OC4RS=setpoint;
			OC4CON=0x000E;
			OC4CON|=0x8000;	// PWM On
			return 1;
		case 11:
			pinmode(11, OUTPUT);
			OC2CON=0;		// PWM Off
			OC2R=setpoint;	// Timer3 will be compared to this values
			OC2RS=setpoint;
			OC2CON=0x000E;
			OC2CON|=0x8000;	// PWM On
			return 1;
		case 12:
			pinmode(12, OUTPUT);
			OC5CON=0;		// PWM Off
			OC5R=setpoint;	// Timer3 will be compared to this values
			OC5RS=setpoint;
			OC5CON=0x000E;
			OC5CON|=0x8000;	// PWM On
			return 1;
		case 13:
			pinmode(13, OUTPUT);
			OC1CON=0;		// PWM Off
			OC1R=setpoint;	// Timer3 will be compared to this values
			OC1RS=setpoint;
			OC1CON=0x000E;
			OC1CON|=0x8000;	// PWM On
			return 1;
		default:
			return 0;
	}
#endif

#if defined(GENERIC32MX250F128)||defined(GENERIC32MX220F032)
	switch (pin)
	{
		case 1:
			pinmode(1, OUTPUT);
			OC3CON=0;		// PWM Off
			OC3R=setpoint;	// Timer3 will be compared to this values
			OC3RS=setpoint;
			OC3CON=0x000E;
			OC3CON|=0x8000;	// PWM On
			return 1;
		case 2:
			pinmode(2, OUTPUT);
			OC4CON=0;		// PWM Off
			OC4R=setpoint;	// Timer3 will be compared to this values
			OC4RS=setpoint;
			OC4CON=0x000E;
			OC4CON|=0x8000;	// PWM On
			return 1;
		case 6:
			pinmode(6, OUTPUT);
			OC2CON=0;		// PWM Off
			OC2R=setpoint;	// Timer3 will be compared to this values
			OC2RS=setpoint;
			OC2CON=0x000E;
			OC2CON|=0x8000;	// PWM On
			return 1;
		case 7:
			pinmode(7, OUTPUT);
			OC5CON=0;		// PWM Off
			OC5R=setpoint;	// Timer3 will be compared to this values
			OC5RS=setpoint;
			OC5CON=0x000E;
			OC5CON|=0x8000;	// PWM On
			return 1;
		case 8:
			pinmode(8, OUTPUT);
			OC1CON=0;		// PWM Off
			OC1R=setpoint;	// Timer3 will be compared to this values
			OC1RS=setpoint;
			OC1CON=0x000E;
			OC1CON|=0x8000;	// PWM On
			return 1;
		default:
			return 0;
	}
#endif
	
#if defined(PIC32_PINGUINO_MICRO)
	switch (pin)
	{
		case 10:
			pinmode(pin, OUTPUT);
			OC2CON=0;		// PWM Off
			OC2R=setpoint;	// Timer3 will be compared to this values
			OC2RS=setpoint;
			OC2CON=0x000E;
			OC2CON|=0x8000;	// PWM On
			return 1;
		case 11:
			pinmode(pin, OUTPUT);
			OC3CON=0;		// PWM Off
			OC3R=setpoint;	// Timer3 will be compared to this values
			OC3RS=setpoint;
			OC3CON=0x000E;
			OC3CON|=0x8000;	// PWM On
			return 1;
		case 12:
			pinmode(pin, OUTPUT);
			OC4CON=0;		// PWM Off
			OC4R=setpoint;	// Timer3 will be compared to this values
			OC4RS=setpoint;
			OC4CON=0x000E;
			OC4CON|=0x8000;	// PWM On
			return 1;
		case 13:
			pinmode(pin, OUTPUT);
			OC5CON=0;		// PWM Off
			OC5R=setpoint;	// Timer3 will be compared to this values
			OC5RS=setpoint;
			OC5CON=0x000E;
			OC5CON|=0x8000;	// PWM On
			return 1;
		default:
			return 0;
	}
#endif

#if defined(PIC32_PINGUINO) || defined(PIC32_PINGUINO_OTG)
	switch (pin)
	{
		case 2:
			TRISDSET=0x10;
			TRISDCLR=0x01;
			OC1CON=0;
			OC1R=setpoint;
			OC1RS=setpoint;
			OC1CON=0x000E;
			OC1CON|=0x8000;
			return 1;
			break;
		case 1:
			TRISDCLR=0x08;
			OC4CON=0;
			OC4R=setpoint;
			OC4RS=setpoint;
			OC4CON=0x000E;
			OC4CON|=0x8000;
			return 1;
			break;
		case 0:
			TRISDCLR=0x04;
			OC3CON=0;
			OC3R=setpoint;
			OC3RS=setpoint;
			OC3CON=0x000E;
			OC3CON|=0x8000;
			return 1;
			break;
		default:
			return 0;
	}		
#endif
#if defined(EMPEROR460) || defined(EMPEROR795)
	switch (pin)
		{
			case  0:
			case 72: TRISDCLR=0x01;
					 OC1CON=0;
					 OC1R=setpoint;
					 OC1RS=setpoint;
					 OC1CON=0x000E;
					 OC1CON|=0x8000;
					 return 1;
					 break;
			case  1:
			case 69: TRISDCLR=0x02;
					 OC2CON=0;
					 OC2R=setpoint;
					 OC2RS=setpoint;
					 OC2CON=0x000E;
					 OC2CON|=0x8000;
					 return 1;
					 break;
			case  2:
			case 68: TRISDCLR=0x04;
					 OC3CON=0;
					 OC3R=setpoint;
					 OC3RS=setpoint;
					 OC3CON=0x000E;
					 OC3CON|=0x8000;
					 return 1;
					 break;
			case  3:
			case 67: TRISDCLR=0x08;
					 OC4CON=0;
					 OC4R=setpoint;
					 OC4RS=setpoint;
					 OC4CON=0x000E;
					 OC4CON|=0x8000;
					 return 1;
					 break;
			case  4:
			case 66: TRISDCLR=0x10;
					 OC5CON=0;
					 OC5R=setpoint;
					 OC5RS=setpoint;
					 OC5CON=0x000E;
					 OC5CON|=0x8000;
					 return 1;
					 break;
			default: return 0;
		}		
#endif
#if defined(UBW32_460) || defined(UBW32_795)
	switch (pin)
		{
			case  0:
			case 40: TRISDCLR=0x01;
					 OC1CON=0;
					 OC1R=setpoint;
					 OC1RS=setpoint;
					 OC1CON=0x000E;
					 OC1CON|=0x8000;
					 return 1;
					 break;
			case  1:
			case 43: TRISDCLR=0x02;
					 OC2CON=0;
					 OC2R=setpoint;
					 OC2RS=setpoint;
					 OC2CON=0x000E;
					 OC2CON|=0x8000;
					 return 1;
					 break;
			case  2:
			case 44: TRISDCLR=0x04;
					 OC3CON=0;
					 OC3R=setpoint;
					 OC3RS=setpoint;
					 OC3CON=0x000E;
					 OC3CON|=0x8000;
					 return 1;
					 break;
			case  3:
			case 45: TRISDCLR=0x08;
					 OC4CON=0;
					 OC4R=setpoint;
					 OC4RS=setpoint;
					 OC4CON=0x000E;
					 OC4CON|=0x8000;
					 return 1;
					 break;
			case  4:
			case 60: TRISDCLR=0x010;
					 OC5CON=0;
					 OC5R=setpoint;
					 OC5RS=setpoint;
					 OC5CON=0x000E;
					 OC5CON|=0x8000;
					 return 1;
					 break;
			default: return 0;
		}		
#endif
}
Example #21
0
void setup()
{
    
    pinmode(USERLED, OUTPUT);     
}
Example #22
0
//////////////////////////////////////////////////////////////////////////////////
// LED Blinker
//////////////////////////////////////////////////////////////////////////////////
void lb_setup() {
  // LED_Blinker setup
  pinmode(LB_LED_PIN,OUTPUT);
  lb_state = LB_S_WAIT_HIGH;
  start_ms_timer(&lb_timer, 1000);
}
Example #23
0
void setup() 
{
	led1=1;
	led2=7;
	pinmode(0,OUTPUT);
	pinmode(1,OUTPUT);
	pinmode(2,OUTPUT);
	pinmode(3,OUTPUT);
	pinmode(4,OUTPUT);
	pinmode(5,OUTPUT);
	pinmode(6,OUTPUT);
	pinmode(7,OUTPUT);
	pinmode(8,OUTPUT);
	pinmode(9,OUTPUT);
	pinmode(10,OUTPUT);
	pinmode(11,OUTPUT);
	pinmode(12,OUTPUT);
}
Example #24
0
void setup() 
{
for (i=0;i<8;i++) pinmode(i,OUTPUT);
Example #25
0
void setup(void)
{
pinmode(0,OUTPUT);	// test caractères
}
Example #26
0
// enable/disable blinking of USERLED on IR processing
void IRrecv_blink13(u8 blinkflag)
{
  irparams.blinkflag = blinkflag;
  if (blinkflag)
    pinmode(USERLED, OUTPUT);
}
Example #27
0
/*	-----------------------------------------------------------------------
---------- KS_DHTRead()
-----------------------------------------------------------------------
* Description:	reads the dht22 device via 1-wire bus 
* Arguments:	
dhpin = pin number where one wire bus is connected.
dh = data record
return errorcode or 0
--------------------------------------------------------------------*/
u8 KS_DHTRead(u8 dhpin,KS_DHT_Data * dh)
{
u16 timeout;
double h,t;
u8 DHTDAT[5]={0};
u8 DHTCHECKSUM;
u8 i,j;
u8 dhtbyte=0;

h=0;
t=0;
if (digitalread(dhpin)==LOW) {return 1;}	 // Bus not free
pinmode(dhpin,OUTPUT); 
digitalwrite(dhpin,LOW);	 // MCU start signal (>=500us) 
Delayms(1);
//Request Data
pinmode(dhpin,INPUT);
timeout = wt; 
while(digitalread(dhpin)) {timeout--;if (timeout==0) {return 2;}}	 // Wait for DHT’s response (20-40us)
timeout = wt;
while(!digitalread(dhpin)) {timeout--;if (timeout==0) {return 3;}}	 // Response signal (80us)
timeout = wt;	
while(digitalread(dhpin)) {timeout--;if (timeout==0) {return 4;}}	 // Preparation for sending data (80us)
//Read Data
for(i=0;i<5;i++)
{
for(j=1;j<=8;j++)
{
timeout = wt;
while(digitalread(dhpin)==LOW) {timeout--;if (timeout==0) {return 5;}}	 // Start to transmit 1-Bit (50 us)
Delayus(30);
dhtbyte <<= 1;
if (digitalread(dhpin))	 // Hi > 30us (70 us) -> Bit=1	
{
dhtbyte |= 1;
timeout = wt;
while(digitalread(dhpin)) {timeout--;if (timeout==0) {return 6;}}	
}	 // Hi < 30us (26-28 us) -> Bit=0	
}
DHTDAT[i] = dhtbyte;
}

DHTCHECKSUM = DHTDAT[0]+DHTDAT[1]+DHTDAT[2]+DHTDAT[3];
if (DHTCHECKSUM != DHTDAT[4]) // Checksum	
{
return 7;	
}	
dh->sign = 0; 

if (DHTDAT[2] & 0b11111000)	// test if sign is set, i.e. negative
{	
dh->sign = 1;
DHTDAT[2] = (DHTDAT[2] ^ 0xFFFF) + 1;	// 2's complement conversion
}

h=(DHTDAT[0]<<8)+DHTDAT[1];
t=(DHTDAT[2]<<8)+DHTDAT[3];
dh->hum=h/10;
dh->temp=t/10;
return 0;
}