Hi all,
I upgraded from Teensy 2.0 to a Teensy 3.2
I cannot seem to get this to work now.
Do I have it on the correct pins??
I am using the 3.3V for the Break Beam power
See below for code...
Please Help...
Thank you
I have a Windows 10 Pro OS.
Arduino programming HUD ver. 1.8.9
TeensyduinoInstall ver: 1.52
Board: Teensy 3.2 /3.1
USB Type: "Serial + Keyboard + Mouse + Joystick"
CPU Speed: "24 MHz"
Optimize: "Faster"
Port: Com 3
I upgraded from Teensy 2.0 to a Teensy 3.2
I cannot seem to get this to work now.
Do I have it on the correct pins??
I am using the 3.3V for the Break Beam power
See below for code...
Please Help...
Thank you
I have a Windows 10 Pro OS.
Arduino programming HUD ver. 1.8.9
TeensyduinoInstall ver: 1.52
Board: Teensy 3.2 /3.1
USB Type: "Serial + Keyboard + Mouse + Joystick"
CPU Speed: "24 MHz"
Optimize: "Faster"
Port: Com 3
Code:
#define SENSORPIN 10
#define LEDPIN 13
// Pin 13: Arduino has an LED connected on pin 13
// Pin 11: Teensy 2.0 has the LED on pin 11
// Pin 6: Teensy++ 2.0 has the LED on pin 6
// Pin 13: Teensy 3.0 has the LED on pin 13
// add for Piezo
int piezo = 9;
int duty_cycle = 2.1;
// end add in for Piezo
int keyAllowed = 1;
int key1 = MODIFIERKEY_ALT;
int key2 = KEY_P;
// variables will change:
int sensorState = 0, lastState=0;
void setup() {
// initialize the LED pin as an output:
pinMode(LEDPIN, OUTPUT);
// initialize the sensor pin as an input
digitalWrite(SENSORPIN, HIGH); // turn on the pullup HIGH
// add for Piezo
digitalWrite(piezo, HIGH);
digitalWrite(piezo, LOW);
// end of Piezo
Serial.begin(9600);
// add in for Piezo
pinMode(piezo, OUTPUT);
// end add in for Piezo
}
// added for Piezo
void beep(float frequency, float time) {
for(int i = 0; i < (time / (1000 / frequency)); i ++) {
digitalWrite(piezo, HIGH);
delayMicroseconds(1000000) ; // / (frequency * duty_cycle);
digitalWrite(piezo, LOW);
delayMicroseconds(1000000) ; // / frequency * (1.0 - duty_cycle));
}
}
// end of Piezo
void loop()
{
// read the state of the breakbeam
sensorState = digitalRead(SENSORPIN);
// check if the sensor beam is broken
// if it is, the sensorState is LOW:
if (sensorState == LOW && keyAllowed > 0) {
// turn LED on:
digitalWrite(LEDPIN, HIGH);
// digitalWrite(LEDPIN, LOW);
Keyboard.press(key1);
Keyboard.press(key2);
//add in for Piezo
beep(440, 100);
beep(880,200);
//end add in for Piezo
delay(10);
Keyboard.release(key2);
Keyboard.release(key1);
keyAllowed = 0;
//delay(500); Default Light Curtain Delay 500 ms
// Light Curtain Delay set to 10 seconds (10000 ms) per QA
// Set only on the Thermatrons
delay(500);
}
if (sensorState == HIGH) {
// turn LED off:
digitalWrite(LEDPIN, LOW);
// digitalWrite(LEDPIN, HIGH);
keyAllowed = 1;
delay(10);
}
}
Last edited by a moderator: