/** * Simulates distance sensing for the IR sensors via decreasing the voltage the emitters get and counting the number of times the * sensors sense something */ void calculateIR(int * irLeft, int * irRight, int * irLeftOld, int * irRightOld){ *irLeftOld = *irLeft; *irRightOld = *irRight; /*int el = 160/IR_STEP, bl = 0, er = 160/IR_STEP, br = 0; while(el-bl>1 || er-br>1){ int dacVal = (el+bl)/2; dac_ctr(26, 0, 160-dacVal*IR_STEP); dac_ctr(27, 1, 160-dacVal*IR_STEP); freqout(11, 1, 38000); if(input(10)) bl=dacVal; else el=dacVal; dacVal = (er+br)/2; dac_ctr(26, 0, 160-dacVal*IR_STEP); dac_ctr(27, 1, 160-dacVal*IR_STEP); freqout(1, 1, 38000); if(input(2)) br=dacVal; else er=dacVal; } *irLeft=bl; *irRight=br;*/ *irLeft=*irRight=0; for(int dacVal = 0; dacVal < 160; dacVal += 8) { dac_ctr(26, 0, dacVal); freqout(11, 1, 38000); *irLeft += input(10); dac_ctr(27, 1, dacVal); freqout(1, 1, 38000); *irRight += input(2); } }
int getIR() { irLeft = 0; irRight = 0; for (int dacVal = 0; dacVal < 160; dacVal += 8) { dac_ctr(26, 0, dacVal); freqout(11, 1, 38000); irLeft += input(10); dac_ctr(27, 1, dacVal); freqout(1, 1, 38000); irRight += input(2); } }
int get_val(void) { int val = 0; button = -1; //high(26); //freqout(4, 100, 4000); //low(26); pause(250); while(1) { val *= 10; button = sirc_button(10); if(button == ENTER) { if(val > 500) val = 500; if(val < -500) val = -500; button = -1; break; } else if(button != -1) { high(26); freqout(4, 100, 4000); low(26); if(button >= 0 && button <= 9) val += button; pause(250); button = -1; } } low(26); return val; }
int checkLeft() { int right; freqout(13, 1, 38000); right = input(11); return right; }
int checkRight() { int left; freqout(0, 1, 38000); left = input(1); return left; }
int main() { while (1) { for (int i=0;i<size;i+=2) { freqout(PIN,speed*notes[i+1],notes[i]); } } }
int main() // main function { low(26); // D/A0 & D/A1 to 0 V low(27); while(1) // Main loop { freqout(11, 1, 38000); // Left IR LED light irLeft = input(10); // Check left IR detector freqout(1, 1, 38000); // Repeat for right detector irRight = input(2); print("%c irLeft = %d, irRight = %d", // Display detector states HOME, irLeft, irRight); pause(100); // Pause before repeating } }
void set_mode(void) { button = -1; high(26); freqout(4, 100, 4000); pause(250); while(button == -1) { button = sirc_button(10); if(button != -1) freqout(4, 100, 4000); if(button >-1 && button < 10) { mode = button; break; } } low(26); }
int checkClose(){ irLeft = 0; irRight = 0; distance = ping_cm(8); for(int dacVal = 0; dacVal < 160; dacVal += 8){ dac_ctr(26, 0, dacVal); freqout(11, 1, 38000); irLeft += input(10); dac_ctr(27, 1, dacVal); freqout(1, 1, 38000); irRight += input(2); } if (irLeft<7) { drive_speed(25,0); } else if (irLeft > 9 || irLeft == 0){ drive_speed(0,25); } else { drive_speed(40,40); } if (distance<=5){ fullTurn(90); degrees+=90; end=1; } drive_getTicks(&ticksLeft, &ticksRight); leftDeg = ((ticksLeft * 360) / 332.38128) * 3.25; rightDeg = ((ticksRight * 360) / 332.38128) * 3.25; degrees = degrees + (rightDeg - leftDeg); moved = ticksLeft * 3.25; }
int main() // Main function { // Add startup code here. while(1) { freqout(1, 1, 33000); // Repeat for right detector irRight = input(2); if(ping_cm(8)>50){ //Salida del laberinto drive_speed(64,64); pause (3000); } if(irRight == 1){ // Si no hay pared a la derecha drive_speed(42,42); //Avanza pause(600); high(26); high(27); //drive_goto(25,-26); //Gira derecha drive_speed(32,-32); pause(750); //drive_speed(0,0); low(26); low(27); drive_speed(42,42); //Avanza pause(1200); //drive_speed(0,0); } if(irRight == 0 && ping_cm(8)<10){ //Si hay pared a la derecha y enfrente drive_speed(0,0); //Gira izquierda drive_speed(-32,32); pause(800); drive_speed(0,0); } else{ //Si no hay pared enfrente drive_speed(42,42); pause(50); } } }
int main() // main function { int DO = 22,CLK = 23, DI = 24, CS = 25; sd_mount(DO,CLK,DI,CS); wav_volume(10); freqout(4, 2000, 3000); // Speaker tone: P4, 2 s, 3 kHz while(1) // Endless loop { int wL = input(7); // Left whisker -> wL variable int wR = input(8); // Right whisker -> wR variable //print("%c", HOME); // Terminal cursor home (top-left) //print("wL = %d wR = %d", wL, wR); // Display whisker variables drive_speed(128,128); if(input(7)==0 || input(8) == 0) { drive_speed(0,0); pause(500); wav_play("ouch.wav"); drive_goto(-64,64); } } }
int main(void) // main function { int distance; int addr = 32769; // Pick EEPROM base address. int side = 1; // 0=Left, 1=Right int exit = 0; while(!exit) { print("Enter direction (0 - forward, 1 - backward, 2 - Exit): "); // User prompt scan("%d\n", &side); freqout(4, 250, 3000); //pin, duration, frequency switch(side) { case 0: // forward with turn high(26); pause(300); drive_speed(-25, 26); //90deg Left turn pause(1000); drive_speed(0, 0); break; case 1: // backward with turn high(27); pause(300); drive_speed(26, -25); //90deg Right turn pause(1000); drive_speed(0, 0); break; case 2: print("Exit"); exit = 1; } } print("\xff\x00\x00"); }
int revisarDerecha(){ freqout(1,1,38000); return (input(2)); }
int main() // main function { freqout(4, 1000, 3000); // pin, duration, frequency }