Using a piezo with digit shield

Store Forums Digit Shield Bugs/Problems Using a piezo with digit shield

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #609
    jjbtlb
    Member

    I modified reaction timer program and added a piezo as a sensor to start program by touching a plate and a led (visual cue) to light when random time ends and led goes out and time stops when plate is touched again, works great. I tried adding a piezo as a buzzer (audio cue) that starts the same time when led light comes on, but want it to go out 250ms latter. having no luck, seems to affect the way program runs. and for some reason the counter only goes up to 32 seconds and stop count and each display dp lights up. Can anyone help me with the code and why counter stop at 32 seconds? Code below

    #include

    unsigned long start, stop;
    const int knockSensor = A1;
    const int ledPin = 9;
    cont int buzzer = 10

    void setup() {
    randomSeed(analogRead(0));
    pinMode(ledPin, OUTPUT);

    DigitShield.begin();
    DigitShield.setPrecision(2);
    DigitShield.setBlank(true);
    }

    void loop() {

    while (analogRead(knockSensor) <=10);// wait until plate is touched
    DigitShield.setBlank(true);// turn off the display
    delay(random(2000, 5000));// delay from 2 to 5 seconds
    digitalWrite(ledPin, HIGH);
    tone(10,2000);
    start = millis();
    if (millis() – start >=250){
    noTone(10);
    DigitShield.setBlank(false);

    while (true) {
    DigitShield.setValue((int)(millis() – start)/1000.0);
    if (analogRead(knockSensor) >=1) {
    stop = millis();
    break;
    }
    }
    digitalWrite(ledPin, LOW);
    DigitShield.setValue((int)(stop-start)/1000.0);
    DigitShield.setBlank(false);
    delay(1000);
    }

    #1640
    Michael
    Keymaster

    The largest value for an int is 32767, so you need to use a “long”. That is why the counter only goes up to 32 seconds.

    #1642
    jjbtlb
    Member

    Changed to long, counter is now counting up to 99.99 thanks

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.