Exemplo n.º 1
0
// Returns the keykode of the pressed key, or NO_KEY if no key is pressed
char Keypad_getKey(){
    
    char key = NO_KEY; // Assume that no key is pressed, this is the default return for getKey()
    unsigned char c,r;    

	


    for (c=0; c<keypad_columns; c++){
		digitalwrite(columnPins[c],LOW);	// Activate the current column.
		for (r=0; r<keypad_rows; r++){	// Scan all the rows for a key press.
			//  The user pressed a button for more then debounceTime microseconds.
			if (currentKey == userKeymap[c+(r*keypad_columns)]){
				// Button hold
				if (((millis()-lastUpdate) >= holdTime) && digitalread(rowPins[r]) == LOW){
					Keypad_transitionTo(HOLD);
				}
				// Button release
				if (((millis()-lastUpdate) >= debounceTime) && digitalread(rowPins[r]) == HIGH){
					Keypad_transitionTo(RELEASED);
					currentKey = NO_KEY;
				}
			} 
			// Button pressed event.  The user pressed a button.
			else if (((millis()-lastUpdate) >= debounceTime) && digitalread(rowPins[r]) == LOW){
				digitalwrite(columnPins[c],HIGH);	// De-activate the current column.
				key = userKeymap[c+(r*keypad_columns)];
				lastUpdate = millis();
				goto EVALUATE_KEY; 			// Save resources and do not attempt to parse two keys at a time
			} 
		}
		digitalwrite(columnPins[c],HIGH);	// De-activate the current column.
	}
	
	EVALUATE_KEY:
 	//if (key != NO_KEY && key != currentKey ){ //Error: keeps repeating keys in the same column

	if (key != NO_KEY && key != currentKey && state!=PRESSED){ //Correction for simultaneous pressed keys on the same row

		
		// if(state ==HOLD && key != currentKey) //try to disable several keys pressed at the same time
		// 	return NO_KEY;
		 

	
		currentKey = key;
		Keypad_transitionTo(PRESSED);
		
		
		
		return currentKey;
	} 
	
	else{
		return NO_KEY;
	}
}
Exemplo n.º 2
0
void loop() {
//
//
//
 	if (!digitalread(I)) izquierda();
//
	if (!digitalread(D))  derecha();
	ServoWrite(LI,500); // enciende los led y varia su brillo
	ServoWrite(LD,20);
	adelante();
	
}
Exemplo n.º 3
0
void loop()
{
if (serial_available())
	{
	digitalwrite(0,HIGH);
	caractere=serial_read();
	serial_write("test");
	if (caractere=='A') digitalwrite(1,digitalread(1)^1);
	}
}
Exemplo n.º 4
0
int sensordigital(int valor)
{
/*funcion para cambiar el valor de los sens digitales (estan invertidos con respecto a la placa)*/
	int temp=0;
	temp=digitalread(valor);
	if (temp==0)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
Exemplo n.º 5
0
unsigned int touch_readData(){
    unsigned char nop;
    unsigned int data = 0;
    unsigned char count;
    
    for(count=0; count<12; count++) {
	data <<= 1;
	digitalwrite(T_CLK, HIGH);	          
	nop++;
	digitalwrite(T_CLK, LOW);	
	nop++;
	if (digitalread(T_DOUT))
	    data++;
    }
    return(data);
}
Exemplo n.º 6
0
unsigned char touch_dataAvailable(){
  unsigned char avail;
  avail = !digitalread(T_IRQ);
  return avail;
}
Exemplo n.º 7
0
void Timer3Interrupt()
{
    if (IntGetFlag(INT_TIMER3)) // Timer3 interrupt ?
    {
        irdata = digitalread(irparams.recvpin);

        irparams.timer++; // One more 50us tick
        
        // Buffer overflow ?
        if (irparams.rawlen >= RAWBUF)
            irparams.rcvstate = STATE_STOP;

        switch(irparams.rcvstate)
        {
            // In the middle of a gap
            case STATE_IDLE:
                if (irdata == MARK)
                {
                    // Not big enough to be a gap.
                    if (irparams.timer < GAP_TICKS)
                        irparams.timer = 0;

                    // gap just ended, record duration and start recording transmission
                    else
                    {
                        irparams.rawlen = 0;
                        irparams.rawbuf[irparams.rawlen++] = irparams.timer;
                        irparams.timer = 0;
                        irparams.rcvstate = STATE_MARK;
                    }
                }
                break;

            // timing MARK
            case STATE_MARK:

                // MARK ended, record time
                if (irdata == SPACE)
                {
                  irparams.rawbuf[irparams.rawlen++] = irparams.timer;
                  irparams.timer = 0;
                  irparams.rcvstate = STATE_SPACE;
                }
                break;

            // timing SPACE
            case STATE_SPACE:

                // SPACE just ended, record it
                if (irdata == MARK)
                {
                    irparams.rawbuf[irparams.rawlen++] = irparams.timer;
                    irparams.timer = 0;
                    irparams.rcvstate = STATE_MARK;
                } 

                // SPACE
                else
                {
                    // big SPACE, indicates gap between codes
                    // Mark current code as ready for processing
                    // Switch to STOP
                    // Don't reset timer; keep counting space width
                    if (irparams.timer > GAP_TICKS)
                        irparams.rcvstate = STATE_STOP;
                }
                break;

            // waiting, measuring gap
            case STATE_STOP:

                // reset gap timer
                if (irdata == MARK)
                    irparams.timer = 0;
                break;
        }

        if (irparams.blinkflag)
        {
            if (irdata == MARK)
                digitalwrite(USERLED, 1);  // turn USERLED on
            else
                digitalwrite(USERLED, 0);  // turn USERLED off
        }

        // Timer3 flag reset
        IntClearFlag(INT_TIMER3);
    }
}
void loop(){ // run over and over again	
	char x, y;	
	uchar tempC;
	
	if (counter>9){		
		counter = 0;
		sec++;
	}
	
//
	sensor = analogRead(SENSOR);
	
	if (sec>59){
		sec = 0;
		min++;
	}
	
	if (min>59){
		min = 0;
		hour++;
	}
	
	if (hour>23){
		hour = 0;
	}
	
	SelectFont(VerdanaNumbers, BLACK);
	GotoXY(3,0);
	
	if (hour < 10)
		PutChar('0');
	PrintNumber(hour);
	
	PutChar(':');
	if (min < 10)
		PutChar('0');
	PrintNumber(min);
	
	PutChar(':');
	if (sec < 10)
		PutChar('0');
	PrintNumber(sec);
		
//
	if(!(digitalread(HOUR))){
		hour++;
	}
	if(!(digitalread(MIN))){
		min++;
	}
				
//
	DrawCircle(21,43,18,BLACK);
//
	x = (int) RSEC * sinf(sec*0.10472);
	y = (int) RSEC * cosf(sec*0.10472);
	DrawLine(21,43,21+x,43-y, BLACK);
//
	x = (int) RMIN * sinf(min*0.10472);
	y = (int) RMIN * cosf(min*0.10472);
	DrawLine(21,43,21+x,43-y, BLACK);
//
	x = (int) RHOUR * sinf((hour>12?hour-12:hour)*0.5236);
	y = (int) RHOUR * cosf((hour>12?hour-12:hour)*0.5236);
	DrawLine(21,43,21+x,43-y, BLACK);
	
	DrawRoundRect(63, 28, 50, 30, 10, BLACK); 
//
//
//
	
	tempC  = (int)(0.48876 * sensor);
//
	
	SelectFont(VerdanaNumbers, BLACK);
	GotoXY(70,32);
	PrintNumber(tempC);
//
	Puts(";");

//
	Delayms(25); //just a fine tune to get 100ms with this!
	
	if(!counter)
		ClearScreenX();         // clear the screen
	
	counter++;
 }
Exemplo n.º 9
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;
}
Exemplo n.º 10
0
void toggle(u8 pin)
{
	digitalwrite(pin, digitalread(pin)^1);
}