task main() { HTSPBsetupIO(HTSPB, 0x10); HTSPBwriteAnalog(HTSPB, HTSPB_DACO0, DAC_MODE_SQUAREWAVE, TONE_C4, 1023); wait1Msec(200); HTSPBwriteAnalog(HTSPB, HTSPB_DACO0, DAC_MODE_SQUAREWAVE, TONE_DS4, 1023); wait1Msec(400); HTSPBwriteAnalog(HTSPB, HTSPB_DACO0, DAC_MODE_SQUAREWAVE, TONE_E4, 1023); wait1Msec(200); HTSPBwriteAnalog(HTSPB, HTSPB_DACO0, DAC_MODE_SQUAREWAVE, 1, 0); wait1Msec(200); HTSPBwriteAnalog(HTSPB, HTSPB_DACO0, DAC_MODE_SQUAREWAVE, TONE_F4, 1023); HTSPBwriteAnalog(HTSPB, HTSPB_DACO1, DAC_MODE_SQUAREWAVE, TONE_A4, 1023); wait1Msec(200); HTSPBwriteAnalog(HTSPB, HTSPB_DACO0, DAC_MODE_SQUAREWAVE, TONE_E4, 1023); HTSPBwriteAnalog(HTSPB, HTSPB_DACO1, DAC_MODE_SQUAREWAVE, TONE_G4, 1023); wait1Msec(200); HTSPBwriteAnalog(HTSPB, HTSPB_DACO0, DAC_MODE_SQUAREWAVE, TONE_C4, 1023); HTSPBwriteAnalog(HTSPB, HTSPB_DACO1, DAC_MODE_SQUAREWAVE, TONE_E4, 1023); wait1Msec(400); HTSPBwriteAnalog(HTSPB, HTSPB_DACO0, DAC_MODE_SQUAREWAVE, 1, 0); HTSPBwriteAnalog(HTSPB, HTSPB_DACO1, DAC_MODE_SQUAREWAVE, 1, 0); }
task main() { int inputdata; ubyte outputdata; int bit; // Set B0 as output HTSPBsetupIO(HTSPB, 0x1); while(true) { // Read a 10bit wide analogue value from A0 inputdata = HTSPBreadADC(HTSPB, 2, 10); float wrist = (inputdata - rMin); wrist /= (rMax - rMin); servo [wristMain] = 255 * wrist; nxtDisplayTextLine(1, "A2: %d", inputdata); nxtDisplayTextLine(3, "W: %1.2f", wrist); // Set the output bit based on the analogue input value bit = (inputdata/128); if (bit > 5) bit = 5; outputdata = 1 << bit; HTSPBwriteIO(HTSPB, outputdata); wait1Msec(50); } }
task main() { int sonarvalue; ubyte outputdata; int bit; // The data to be written: 0x3F = 111111 binary, // makes all digital ports outputs. HTSPBsetupIO(HTSPB, 0x3F); while(true) { // Get the value from the LEGO sound sensor. sonarvalue = SensorValue(US_PORT); // Set the output bit based on the analogue input value bit = sonarvalue / 10; if (bit > 5) bit = 5; outputdata = 1 << bit; eraseDisplay(); nxtDisplayTextLine(1, "%d", sonarvalue); HTSPBwriteIO(HTSPB, outputdata); wait1Msec(50); } }
void init(){//**********************************INIT****************** HTSPBsetupIO(HTPB,0b00111000);//0 in 1 out //light up for battery servo[bucket]=120; ubyte in=HTSPBreadIO(HTPB,0b00001111);//get autonomous settings! bDisplayDiagnostics=false; nMotorEncoder[back]=0; nMotorEncoder[grab]=0; nMotorEncoder[motorC]=0; ClearTimer(T4); HTSPBwriteIO(HTPB,turning); while(nNxtButtonPressed!=3){ if(HTSPBreadIO(HTPB,0b01000000)>0)STARTINGPOS=1; else STARTINGPOS=0; delay=(int)(30000.0*((float)readAnalogInput(HTPB,0)/1023.0)); nxtDisplayCenteredBigTextLine(0,"WAITING!"); nxtDisplayCenteredBigTextLine(2,"%d",HTSPBreadIO(HTPB,0b11111111)); nxtDisplayCenteredBigTextLine(4,"%d",STARTINGPOS); nxtDisplayCenteredBigTextLine(6,"%d",delay); HTSPBwriteAnalog(HTPB,HTSPB_DACO0,DAC_MODE_SQUAREWAVE,1,620); } HTSPBwriteAnalog(HTPB,HTSPB_DACO0,DAC_MODE_DCOUT,1,0); eraseDisplay(); nxtDisplayCenteredBigTextLine(0,"READY!"); calibrateGyro(); reset(); }
task main() { // The data to be written: 0x30 = 110000 binary, // makes B4,B5 digital ports outputs. HTSPBsetupIO(HTSPB, 0x03); while(true) { // Turn off the LED HTSPBwriteIO(HTSPB, 0x00); eraseDisplay(); nxtDisplayTextLine(2, "running"); // Wait a random time between 3 and 8 seconds. wait1Msec(random(5000) + 3000); // Switch on the LED and reset the timer HTSPBwriteIO(HTSPB, 0x01); time1[T1] = 0; // Wait for user to press the stop button while (HTSPBreadIO(HTSPB, 0x30) != 0x10) { wait1Msec(5); } eraseDisplay(); nxtDisplayTextLine(2, "Time: %d", time1[T1]); // Wait for user to reset while (HTSPBreadIO(HTSPB, 0x30) != 0x30) { wait1Msec(5); } } }
void initializeRobot () { HTSPBsetupIO(HTSPB, 0x3); setGrabber (grabberTarget/100.0); setWrist (wristTarget/1000.0); /* If the wrist is moving too quickly try changing the divisor in the setWrist equation from 1000.0 to 10000.0; this will not make a huge difference, but it's worth a try. */ servo [rampLatch] = rampLatchClosed; }
task test(){ HTSPBsetupIO(HTSPB, 0b11111000); while(true){ HTSPBwriteIO(HTSPB, 0b00001000); wait10Msec(100); HTSPBwriteIO(HTSPB, 0b00000000); wait10Msec(100); } }
void init(){ bDisplayDiagnostics=false; // StartTask(batteryTask); HTSPBsetupIO(HTPB,0b11110000); batteryUpdate(HTPB); nMotorEncoder[grab]=0; servo[bucket]=81; }
task main() { // The data to be written: 0x10 = 010000 binary, // makes B4 digital port an output. HTSPBsetupIO(HTSPB, 0x10); while(true) { if(HTSPBreadIO(HTSPB, 0x01) == 0) { eraseDisplay(); displayTextLine(1, "Magnet present"); HTSPBwriteIO(HTSPB, 0x10); } else { eraseDisplay(); displayTextLine(1, "Magnet absent"); HTSPBwriteIO(HTSPB, 0x00); } wait1Msec(50); } }
task main() { int inputdata; // Set B0 for output HTSPBsetupIO(HTSPB, 0x1); while(true) { // Read a 10bit wide analogue value from A0 inputdata = HTSPBreadADC(HTSPB, 0, 10); nxtDisplayTextLine(1, "A0: %d", inputdata); // If A0 is less than 50% of the max value // turn off the LED, otherwise switch it on if(inputdata < 512) HTSPBwriteIO(HTSPB, 0x00); else HTSPBwriteIO(HTSPB, 0x01); wait1Msec(50); } }
task main() { HTSPBsetupIO(HTSPB, 0x10); while(true) { // Read the value from the temp sensor inputdata = HTSPBreadADC(HTSPB, 0, 10); // Convert to an actual temperature temperatureC = ((inputdata*3300)/1023-600)/10.0; nxtDisplayTextLine(1, "Temp: %d C", temperatureC); // If we're above 28 degrees, switch on the LED if(temperatureC > THRESHOLD) { HTSPBwriteIO(HTSPB, 0x10); } else { HTSPBwriteIO(HTSPB, 0x00); } wait1Msec(50); } }
task main() { int inputdata; ubyte outputdata; int bit; // Set B0 as output HTSPBsetupIO(HTSPB, 0xFF); while(true) { // Read a 10bit wide analogue value from A0 inputdata = HTSPBreadADC(HTSPB, 0, 10); displayTextLine(1, "A0: %d", inputdata); // Set the output bit based on the analogue input value bit = (inputdata/128); if (bit > 5) bit = 5; outputdata = 1 << bit; HTSPBwriteIO(HTSPB, outputdata); wait1Msec(50); } }
task main() { short inputdata; ubyte outputdata; short bit; // Set all digital IOs as outputs as output HTSPBsetupIO(HTSPB, 0xFF); while(true) { // Read a 10bit wide analogue value from A0 inputdata = HTSPBreadADC(HTSPB, 0, 10); displayTextLine(1, "A0: %d", inputdata); // Set the output bit based on the analogue input value bit = (inputdata/128); if (bit > 5) bit = 5; displayTextLine(2, "Bit: %d", bit); outputdata = 1 << bit; HTSPBwriteIO(HTSPB, outputdata); sleep(50); } }
void init(){ HTSPBsetupIO(HTPB,0b11000000); //light up for battery batteryUpdate(HTPB); servo[bucket]=120; ubyte in=HTSPBreadIO(HTPB,0b00001111);//get autonomous settings! bDisplayDiagnostics=false; nMotorEncoder[back]=0; nMotorEncoder[grab]=0; nMotorEncoder[motorC]=0; int sum=0; for(int i=0;i<5;i++){ sum+=readAnalogInput(HTPB,1); wait1Msec(100); } stationaryVoltage=sum/5; while(nNxtButtonPressed!=3){ if(HTSPBreadIO(HTPB,0b00000100)>0)STARTINGPOS=1; nxtDisplayCenteredBigTextLine(4,"%d",STARTINGPOS); } nxtDisplayCenteredBigTextLine(0,"WAITING"); }