so to start, i am new to coding and these arduino (teensy) boards, but i succesfully programmed 1 of my 2 boards to be a keyboard command of "space bar" when a button is pressed and not allow another button press for 2000ms, but i am now trying to program a second teensy board to be the key board commands of "control+p" in order to print something, and turn on a light for a certain amount of time. is there anyone that can look through my code and help me out with this? i tried to take the code from my spacebar button and modify it for this new command, but i do not know if i did it right, or how to incorporate the light in to the circuit as well. attached is a picture of the coding i have copied and modified.
better attach the code as text (optionally between [ code] tags == # button)
I expect people here will not gonna retype the code ..
sorry, here it is. just read the "red this before you post"...
void setup() {
Serial.begin(9600);
pinMode(13, INPUT_PULLUP); //what pin to read
delay(4000); //delay from start up/plug in
}
void loop() {
if (digitalRead(13) == HIGH) { //what pin to read
delay(10); //how long to hold button
} else {
// press and hold CTRL
Keyboard.set_modifier(MODIFIERKEY_CTRL);
Keyboard.send_now();
// press P while still holding CTRL
Keyboard.set_modifier(MODIFIERKEY_CTRL | KEY_P);
Keyboard.send_now();
// release all the keys at the same instant
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
delay(20000); //delay until next button push is allowed in "ms"
}
delay(10); //delay in "ms"
}
// This is new code, hopefully to activiate a light on button push. copied from arduino.cc/tutorial/button
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 11; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW delay(2000) );
}
}
jsclimbn:
sorry, here it is. just read the "red this before you post"...else {
// turn LED off:
digitalWrite(ledPin, LOW delay(2000) );
}
I think you mean:
digitalWrite(ledPin, LOW);
delay(2000);
that change did help, but now i am caught up with another error
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino: 1.0.5 (Mac OS X), Board: "Teensy 2.0"
Print_Button:38: error: expected constructor, destructor, or type conversion before '(' token
Print_Button:40: error: expected constructor, destructor, or type conversion before '(' token
Print_Button:41: error: expected declaration before '}' token
thanks to all the help, i got my code to work. not when pin 13 is shorted to ground, a keyboard command of apple+p is clicked, followed by return 10ms later. at the same time, the led on the board lights up for 20 seconds and turns off. the point of this was for a photo booth where after the guests are done with their session, and 1 print is made, a second print can be made by push of a single button. no users have to touch the computer or keyboard.
Can yo post your working code as a future reference for others who find this thread?
Thank you