<\/a><\/p>\nY el c\u00f3digo es el siguiente:<\/p>\n
[sourcecode language=\u00bbpy\u00bb]<\/p>\n
\/\/ Serial control 2 servos seguidores
\n\/\/ Walii.es 2010
\n#define RUNLED PORTAbits.RA4
\n#define PIC18F4550 \/\/ control pin of servo
\nint counter; \/\/ counter used for interrupt
\nint position0; \/\/pin0 servo vertical
\nint ir0;\/\/pin 13
\nint ir1;\/\/pin 14
\nint ir2;\/\/pin 15
\nint ir3;\/\/pin 16
\nint Pot=900; \/\/sensibilidad de los LDRs
\nint i;
\nint key;
\nint pulseWidth = 20;
\nvoid setup()
\n{
\nT1CON=0x01; \/\/ configure timer 1
\nPIE1bits.TMR1IE=1; \/\/ set interrupt for timer 1
\nINTCON|=0xA0; \/\/ enable GIE and PEIE
\nfor (i=0;i<3;i++) { \/\/servos conections
\npinMode(i,OUTPUT);
\n}
\nSerial.begin(9600);
\n}
\nvoid UserInterrupt()
\n{
\nif (PIR1bits.TMR1IF)
\n{
\nTMR1H=0xFF; \/\/ reload value timer 1
\nTMR1L=0x9C;
\nPIR1bits.TMR1IF=0; \/\/ clear interrupt flag
\nif (counter>position0+51) PORTBbits.RB0=0; \/\/ position
\nelse PORTBbits.RB0=1;
\nif (counter==1500) counter=0; \/\/ value for ~20 mS
\ncounter++;
\n}
\n}
\nvoid loop()
\n{
\n\/\/En principio utilizo solo dos LDRs pero se pueden usar 4
\n\/\/I use only two LDRs but you can use 4
\n\/\/Puedes usar LDR o led Infrarrojos
\n\/\/You can use Infrared LEDs or LDR
\nir0=analogRead(13);
\nir1=analogRead(14);
\nir2=analogRead(15);
\nir3=analogRead(16);
\nif Serial.available()
\n{
\nkey=Serial.read();
\nif (key==’1′) position0=position0+10;
\nif (key==’2′) position0=position0-10;
\n}
\n\/\/control de posicion dependiendo la incidencia del sol
\n\/\/ Control position depending on the incidence of the sun
\nif ( ir0 < Pot && ir1 < Pot) position0=position0;\/\/quieto sol incide
\nif ( ir0 < Pot && ir1 > Pot) position0=position0-10;\/\/izquierda
\nif ( ir0 > Pot && ir1 < Pot) position0=position0+10;\/\/derecha
\nif ( ir0 > Pot && ir1 > Pot) position0=position0;\/\/sin sol
\n\/\/control de exceso de posicion de servo
\n\/\/ Position control of servo excess
\nif (position0<1) position0=1;
\nif (position0>151) position0=151;
\n\/\/debug via puerto serie
\n\/\/ Debug via serial port
\nSerial.print(" Posicion serv0 = ");
\nSerial.print(position0);
\nSerial.print("\\n\\r");
\nSerial.print("\\n\\r");
\nSerial.print(" ir0= ");
\nSerial.print(ir0);
\nSerial.print(" ir1= ");
\nSerial.print(ir1);
\n}<\/p>\n
[\/sourcecode]<\/p>\n
Nota: he pensado que ser\u00eda \u00fatil incluir en el c\u00f3digo y en el circuito un potenci\u00f3metro para controlar manualmente el nivel de sensibilidad.<\/p>\n
Esto se hace por ejemplo: Agregando en la patilla RA5 (patilla ping\u00fcino 17 o del pic 7) el centro de un potenci\u00f3metro o resistencia regulable, y los extremos en 5Volts y tierra.<\/p>\n
Y modificar el siguiente c\u00f3digo.<\/p>\n
int Pot=900;<\/p>\n
por<\/p>\n
int Pot=analogRead(17);<\/p>\n","protected":false},"excerpt":{"rendered":"
Hoy un proyecto f\u00e1cil de replicar, pero que no encontr\u00e9 nada para PINGUINO por eso decid\u00ed hacerlo. La forma de funcionar es la siguiente: Los…<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/posts\/161"}],"collection":[{"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=161"}],"version-history":[{"count":6,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/posts\/161\/revisions"}],"predecessor-version":[{"id":164,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/posts\/161\/revisions\/164"}],"wp:attachment":[{"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}