Пример #1
0
/// Play a chromatic scale.
void playScale(MorseToken) {
  analogWrite(piezoTxN, 0);
  for (size_t i(24); i < sizeof(noteHz)/sizeof(noteHz[0]); i += 1) {
    pwmFrequency(noteHz[i]+0.5);
    pwmWrite(getDuty());
    delayMicroseconds(getDitMicros());
    pwmWrite(0);
  }
}
Пример #2
0
void Heater::update(long int time) 
{
	if(!active)
		return;

	float tPoint = (time % 1000 % cycle);

	// INSIDE HEAT CYCLE
	if(tPoint < duty)
		elementPower(HEATERON);
	else
		elementPower(HEATEROFF);
	
	fprintf(stderr,"TIME %li TP %f stat %d ON %d\n",time,tPoint,getDuty(),(_gpio_status==HEATERON));
}
Пример #3
0
/// Play one of 10 sound effects based on the digit on the stack.
void playSoundEffect(MorseToken code) {
  pwmFrequency(noteHz[48]+0.5);
  pwmWrite(getDuty());
  delayMicroseconds(getDitMicros());
  pwmWrite(0);
  if (symbolStackSize()) {
    uint8_t n(s(0).m2i());
    elapsedMicros t;
    size_t steps[] = { 0, 2, 3, 5, 7, 8, 10 };
    switch (n) {
    case 0:
      t = 0;
      // Low pulsing static rumble
      while (t < 60 * getDitMicrosDefault()) {
	for (int i(1); i < 25; ++i) {
	  dWrite(HIGH);
	  delayMicroseconds((1 + random(i)) * 1136);
	  dWrite(LOW);
	  delayMicroseconds((1 + random(i)) * 1136);
	}
      }
      break;
    case 1:
      shufflingCash(120 * getDitMicrosDefault());
      break;
    case 2:
      t = 0;
      // Descending beats
      while (t < 120 * getDitMicrosDefault()) {
	for (int i(1); i < 75; ++i) {
	  dWrite(HIGH);
	  delayMicroseconds(i * 1136/12);
	  dWrite(LOW);
	  delayMicroseconds(i * 1136/12);
	}
      }
      break;
    case 3:
      t = 0;
      // Buzzer
      while (t < 60 * getDitMicrosDefault()) {
	playTone(noteHz[36], getDitMicrosDefault()/30);
	playTone(noteHz[48], getDitMicrosDefault()/30);
	playTone(noteHz[52], getDitMicrosDefault()/60);
	playTone(noteHz[57], getDitMicrosDefault()/60);
      }
      break;
    case 4:
      t = 0;
      // Humm, kinda like a machine hum.
      while (t < 60 * getDitMicrosDefault()) {
	for (int i(0); i < 49; ++i) {
	  playTone(noteHz[i], getDitMicrosDefault()/10);
	}
      }
      break;
    case 5:
      t = 0;
      // ascending and repeating 
      while (t < 60 * getDitMicrosDefault()) {
	for (int i(0); i < 49; ++i) {
	  playTone(noteHz[i], getDitMicrosDefault()/2);
	}
      }
      break;
    case 6:
      t = 0;
      // ascending more quickly
      while (t < 60 * getDitMicrosDefault()) {
	for (int i(0); i < 49; ++i) {
	  playTone(noteHz[random(1,96)], getDitMicrosDefault()/10);
	}
      }
      break;
    case 7:
      t = 0;
      // ?
      while (t < 60 * getDitMicrosDefault()) {
	for (int i(0); i < 7; ++i) {
	  playTone(noteHz[(24 + steps[i % 7]) % 97], getDitMicrosDefault());
	}
      }
      break;
    case 8:
      t = 0;
      // Almost white noise, like water from a tap
      while (t < 60 * getDitMicrosDefault()) {
	dWrite(HIGH);
	delayMicroseconds(random(100,1000));
	dWrite(LOW);
	delayMicroseconds(random(100,1000));
      }
      break;
    case 9:
      t = 0;
      // Almost white noise, like water from a tap
      while (t < 60 * getDitMicrosDefault()) {
	dWrite(HIGH);
	delayMicroseconds(random(10,8000));
	dWrite(LOW);
	delayMicroseconds(random(10,8000));
      }
      t = 0;
      // Sort of like a pinball machine
      { int i(2);
	while (t < 60 * getDitMicrosDefault()) {
	  for (int k(0); k < 10; ++k) {
	    dWrite(HIGH);
	    delayMicroseconds(i);
	    dWrite(LOW);
	    delayMicroseconds(i);
	  }
	  i <<= 2;
	  if (4000 < i) { i = 2; }
	}
      }
    }
    txString("K");
  } else {
    txError();
  }
}
Пример #4
0
int main()
{
    int cTotal = 0;
    int cState = STATE_READ;

    char toggleOut = FALSE;

    Signal motor1;
    Signal motor2;
    Signal estop;
    Signal rcMode;

    init_coridium();

	setbaud(0, 17);
	
	
    statusMessage[0] = '#';
	statusMessage[1] = '%';
	statusMessage[2] = 0x82;



    INPUT(RC1); motor1.pin = RC1;
    INPUT(RC2); motor2.pin = RC2;
    INPUT(RC3); estop.pin = RC3;
    INPUT(RC4); rcMode.pin = RC4;


    OUTPUT(TX);
    OUTPUT(ESTOP); LOW(ESTOP);
    OUTPUT(RCMode);
    OUTPUT(FreqPin);
    OUTPUT(LIGHT);

    motor1.state = STATE_WAIT;
    motor1.duty = 0;
    motor1.valid = 0;

    motor2.state = STATE_WAIT;
    motor2.duty = 0;
    motor2.valid = 0;

    estop.state = STATE_WAIT;
    estop.duty = 0;
    estop.valid = 0;

    rcMode.state = STATE_WAIT;
    rcMode.duty = 0;
    rcMode.valid = 0;

    SLEEP(2);

    while (TRUE)
    {
        switch (cState)
        {
        case STATE_READ:
            if (toggleOut)
            {
                toggleOut = FALSE;
                HIGH(FreqPin);
            }
            else
            {
                toggleOut = TRUE;
                LOW(FreqPin);
            }

            cTotal += getDuty(&motor1);
            cTotal += getDuty(&motor2);
            cTotal += getDuty(&estop);
            cTotal += getDuty(&rcMode);

            if (cTotal > 8)
            {
                cState = STATE_SERIAL;
                cTotal = 0;
            }
            break;

        case STATE_SERIAL:
			if (estop.lastVal > 0)
            {
                sendESTOP(0);
                gESTOP = FALSE;
				
                if (rcMode.lastVal > 0)
                {
                    HIGH(LIGHT);
                    HIGH(RCMode);

                    // 11 == Manual (teleop) Mode
                    statusMessage[3] = 0x00;
                    statusMessage[4] = 0xFF;
                    statusMessage[5] = 0xFF;
                    statusMessage[6] = 0xFF;

                    calcSum();
					//statusMessage[7] = 0x84;
                    //SEROUT(TXD0,9600, 1, 3, statusMessage);
					TXD0(statusMessage[0]);
					TXD0(statusMessage[1]);
					TXD0(statusMessage[2]);
					TXD0(statusMessage[3]);
					TXD0(statusMessage[4]);
					TXD0(statusMessage[5]);
					TXD0(statusMessage[6]);
					TXD0(statusMessage[7]);
                }
                else
                {
                    if (flashcount > 0)
                    {
                        HIGH(LIGHT);
                    }
                    else
                    {
                        LOW(LIGHT);
                    }

                    if (flashcount > LIGHTDUTY)
                    {
                        flashcount = -LIGHTDUTY;
                    }

                    LOW(RCMode);

                    // 00 == Autonomous Mode
                    statusMessage[3] = 0x00;
                    statusMessage[4] = 0x00;
                    statusMessage[5] = 0x00;
                    statusMessage[6] = 0x00;

                    calcSum();
					//statusMessage[7] = 0x84;
                    //SEROUT(TXD0,9600, 1, 3, statusMessage);
					
					TXD0(statusMessage[0]);
					TXD0(statusMessage[1]);
					TXD0(statusMessage[2]);
					TXD0(statusMessage[3]);
					TXD0(statusMessage[4]);
					TXD0(statusMessage[5]);
					TXD0(statusMessage[6]);
					TXD0(statusMessage[7]);
                }
            }
            else
            {
                HIGH(LIGHT);
                HIGH(RCMode);
                sendESTOP(1);
                gESTOP = TRUE;
				
				// 11 == Manual (teleop) Mode
				statusMessage[3] = 0x00;
				statusMessage[4] = 0xFF;
				statusMessage[5] = 0xFF;
				statusMessage[6] = 0xFF;

				calcSum();
				//statusMessage[7] = 0x84;
				//SEROUT(TXD0,9600, 1, 3, statusMessage);
				TXD0(statusMessage[0]);
				TXD0(statusMessage[1]);
				TXD0(statusMessage[2]);
				TXD0(statusMessage[3]);
				TXD0(statusMessage[4]);
				TXD0(statusMessage[5]);
				TXD0(statusMessage[6]);
				TXD0(statusMessage[7]);
            }

#ifdef DEBUG
            putchar( binToHexstr((char)((motor1.lastVal >> 4) & 0x0F)) );
            putchar( binToHexstr((char)(motor1.lastVal & 0x0F)) );
            putchar(' ');
                        putchar( binToHexstr((char)((motor2.lastVal >> 4) & 0x0F)) );
            putchar( binToHexstr((char)(motor2.lastVal & 0x0F)) );
            putchar('\n');
            //printf("%d\n", estop.lastVal);
#endif
            // motor1 == forward value
            // motor2 == left/right value

            int left_motor = motor1.lastVal/2 - motor2.lastVal/2;
            int right_motor = motor1.lastVal/2 + motor2.lastVal/2;

            sendSerial(right_motor, 1);
            sendSerial(left_motor, 0);

            cState = STATE_READ;

            break;
        }
        flashcount++;
    }

    return 0;
}