Show Posts
|
|
Pages: [1] 2 3 ... 8
|
|
3
|
Using Arduino / Programming Questions / PS/2 Control keyboard + Arduino
|
on: April 20, 2013, 04:04:38 pm
|
Greetings! I am using the PS/2 library found here: http://playground.arduino.cc/Main/PS2KeyboardEverything hardware wise works great. I cannot for the life of me figure out how to put the incoming key strokes, specifically for letters to play well with conditional statements. here is my code attempt..its essentially the same as the example, slightly modified. /* PS2Keyboard library example PS2Keyboard now requries both pins specified for begin()
keyboard.begin(data_pin, irq_pin); Valid irq pins: Arduino Uno: 2, 3 Arduino Due: All pins, except 13 (LED) Arduino Mega: 2, 3, 18, 19, 20, 21 Teensy 2.0: All pins, except 13 (LED) Teensy 2.0: 5, 6, 7, 8 Teensy 1.0: 0, 1, 2, 3, 4, 6, 7, 16 Teensy++ 2.0: 0, 1, 2, 3, 18, 19, 36, 37 Teensy++ 1.0: 0, 1, 2, 3, 18, 19, 36, 37 Sanguino: 2, 10, 11 for more information you can read the original wiki in arduino.cc at http://www.arduino.cc/playground/Main/PS2Keyboard or http://www.pjrc.com/teensy/td_libs_PS2Keyboard.html Like the Original library and example this is under LGPL license. Modified by Cuninganreset@gmail.com on 2010-03-22 Modified by Paul Stoffregen <paul@pjrc.com> June 2010 */ #include <PS2Keyboard.h>
#include "binary.h" typedef uint8_t boolean; typedef uint8_t byte;
const int DataPin = 8; const int IRQpin = 3; //MUST BE PINS 2 OR 3 IF USING ARDUINO UNO
PS2Keyboard keyboard; byte a; int values = 0;
void setup() { delay(1000); keyboard.begin(DataPin, IRQpin); Serial.begin(115200); Serial.println("Keyboard Test:"); }
void loop() { if (keyboard.available()) { // read the next key char c = keyboard.read(); Serial.print(c); // check for some of the special keys if (c == PS2_ENTER) { Serial.println(); } else if (c == PS2_TAB) { Serial.print("[Tab]");
} else if (c == PS2_PAGEDOWN) { Serial.print("[PgDn]"); } else if (c == PS2_PAGEUP) { Serial.print("[PgUp]"); } else if (c == PS2_LEFTARROW) { Serial.print("[Left]"); } else if (c == PS2_RIGHTARROW) { Serial.print("[Right]"); } else if (c == PS2_UPARROW) { Serial.print("[Up]"); } else if (c == PS2_DOWNARROW) { Serial.print("[Down]"); } else if (c == PS2_DELETE) { Serial.print("[Del]"); // } else {
}
} // otherwise, just print all normal characters
while(Serial.available()){ values = Serial.read(); if (values=='a' ){ // Serial.println ("entered A"); }
} } Everything compiles, but Im not sure why this chunk below does not show the print message: while(Serial.available()){ values = Serial.read(); if (values=='a' ){ // Serial.println ("entered A");
|
|
|
|
|
6
|
Using Arduino / Sensors / Re: Two Simultaneous Infrared Sensor Readings
|
on: March 31, 2013, 02:45:28 pm
|
/////pin declaration/////////////////
int analog0 = A0; int analog1 = A1;
int sensor[2] = {analog0, analog1}; //Analog 0 pin const int red_led = 9; //digital pin 9 const int green_led = 7; //digital pin 7
////////////////////////////////////
boolean bool_var = false;
int sense_readings; int i;
////////averager of 20 values////////////////// const int numReadings = 20; //higher the number, more numbers read/averaged. slows program down
int readings[numReadings]; // the readings from the analog input int index = 0; // the index of the current reading int total = 0; // the running total int average = 0; // the average
///////////////////////////////////////////////////
int counter;
void setup(){ Serial.begin(115200); //set your baud rate in arduino serial monitor pinMode(red_led, OUTPUT); pinMode(green_led, OUTPUT);
}
void loop(){ for (i = 0; i < 2; i++) { sense_readings = analogRead(sensor[i]); // Serial.println(sensor[i]); //int new_val = analogRead(sensor[i]); Serial.println(sense_readings); delay(300);
}
}
This seems to print out simultaneously the values of two sensors. Anyone confirm this? it seems fine.
|
|
|
|
|
7
|
Using Arduino / Sensors / Re: Two Simultaneous Infrared Sensor Readings
|
on: March 31, 2013, 02:20:21 pm
|
revised code:
/////pin declaration/////////////////
int sensors[] = {A0,A1}; const int red_led = 9; //digital pin 9 //const int yellow_led = 6; //main indicator/digital pin 6 const int green_led = 7; //digital pin 7
////////////////////////////////////
boolean bool_var = false;
int sensor_pins = sensors[2];
////////averager of 20 values////////////////// const int numReadings = 20; //higher the number, more numbers read/averaged. slows program down int readings2[numReadings]; // the readings from the analog input int readings[numReadings]; // the readings from the analog input int index = 0; // the index of the current reading int total = 0; // the running total int average = 0; // the average
///////////////////////////////////////////////////
int counter;
void setup(){ Serial.begin(115200); //set your baud rate in arduino serial monitor pinMode(red_led, OUTPUT); // pinMode(yellow_led, OUTPUT); pinMode(green_led, OUTPUT);
}
void loop(){
//led_standby(); sensor_read();
}
int sensor_read(){ int read_sensor = analogRead(sensor_pins); digitalWrite(red_led, LOW); digitalWrite(green_led, HIGH); for (int counting=0; counting <=20; counting++){ //this is a counter; number 100 inside is adjustable for longer delay Serial.print("timer = "); Serial.println(counting); // subtract the last reading: total= total - readings[index]; // read from the sensor: readings[index] = read_sensor; // add the reading to the total: total= total + readings[index]; // advance to the next position in the array: index = index + 1;
// if we're at the end of the array... if (index >= numReadings) // ...wrap around to the beginning: index = 0;
// calculate the average: average = total / numReadings; // send it to the computer as ASCII digits Serial.print("averaged sensor readings = "); Serial.println(average); Serial.println();
delay(200); // delay in between reads for stability
while(bool_var ==false && average >= 100){ // The sensor is spaced between the end of the wall by 4ft digitalWrite(red_led, HIGH); digitalWrite(green_led, LOW); counting=0; bool_var = true; break;
} if (counting ==20 && bool_var==true){ Serial.println("SEND A SIGNAL TO IP CAMERA"); digitalWrite(red_led, HIGH); digitalWrite(green_led, LOW); bool_var=false; } else if (average <100 && counting ==20){ digitalWrite(red_led, LOW); digitalWrite(green_led, HIGH); bool_var=false;
} }
}
still not much luck :/
|
|
|
|
|
8
|
Using Arduino / Sensors / Two Simultaneous Infrared Sensor Readings
|
on: March 31, 2013, 12:09:00 am
|
Greetings! I am currently using two infrared distance sensors sold on sparkfun: https://www.sparkfun.com/products/8958I have a simple sketch measuring a single sensor and some filtering. The second sketch I am trying to incorporate an additional IR sensor by putting the analog pins into an array so I may read both sensors values simultaneously. This is my issue; I am not receiving any value from the additional sensor pin. I have eliminated basic hardware issues (enough current, working sensors, testing additional sensor+original code, etc) So this issue is purely code. Here is my sketch thus far: /////pin declaration/////////////////
const int sensor[] = {A0,A1}; //Analog 0 pin const int red_led = 9; //digital pin 9 const int green_led = 7; //digital pin 7
////////////////////////////////////
boolean bool_var = false;
int sense_readings; int i;
////////averager of 20 values////////////////// const int numReadings = 20; //higher the number, more numbers read/averaged. slows program down
int readings[numReadings]; // the readings from the analog input int index = 0; // the index of the current reading int total = 0; // the running total int average = 0; // the average
///////////////////////////////////////////////////
int counter;
void setup(){ Serial.begin(115200); //set your baud rate in arduino serial monitor pinMode(red_led, OUTPUT); pinMode(green_led, OUTPUT);
}
void loop(){ for (i = 0; i < 1; i++) { sense_readings = analogRead(sensor[i]); Serial.println(sensor[i]); } sensor_read();
}
int sensor_read(){
digitalWrite(red_led, LOW); digitalWrite(green_led, HIGH); for (int counting=0; counting <=20; counting++){ //this is a counter; number 100 inside is adjustable for longer delay Serial.print("timer = "); Serial.println(counting); // subtract the last reading: total= total - readings[index]; // read from the sensor: readings[index] = sense_readings; //analogRead(sensor); // add the reading to the total: total= total + readings[index]; // advance to the next position in the array: index = index + 1; // if we're at the end of the array... if (index >= numReadings) // ...wrap around to the beginning: index = 0;
// calculate the average: average = total / numReadings; // send it to the computer as ASCII digits Serial.print("averaged sensor readings = "); Serial.println(average); Serial.println(); delay(300); // delay in between reads for stability while(bool_var ==false && average >= 100){ // The sensor is spaced between the end of the wall by 4ft digitalWrite(red_led, HIGH); digitalWrite(green_led, LOW); counting=0; bool_var = true; break;
} if (counting ==20 && bool_var==true){ Serial.println("SEND A SIGNAL TO IP CAMERA"); digitalWrite(red_led, HIGH); digitalWrite(green_led, LOW); bool_var=false; } else if (average <100 && counting ==20){ digitalWrite(red_led, LOW); digitalWrite(green_led, HIGH); bool_var=false;
} }
}
|
|
|
|
|
9
|
Community / Gigs and Collaborations / Re: Chicago Area Freelancer
|
on: March 20, 2013, 03:21:07 pm
|
|
I'm in Chicago and may be of help.
Refer to my site, danbertner.wordpress.com where you will find my direct contact email in addition to my portfolio.
Please contact me through email and not the Arduino forum.
Cheers!
|
|
|
|
|
12
|
Using Arduino / Programming Questions / Re: Adafruit Wave shield button press song
|
on: January 29, 2013, 11:39:04 am
|
So I tried your suggestion as this being the only chunk in the main loop with the buttonstate added. nothing plays. wave.play(); // make some noise! uint8_t n = 0; while (wave.isplaying) {// playing occurs in interrupts, so we print dots in realtime buttonState = digitalRead(buttonPin);
putstring("."); if (!(++n % 32) && buttonState==HIGH){//Serial.println(); //delay(100); wave.pause(); } else{ wave.resume();
}
}
|
|
|
|
|
14
|
Using Arduino / Programming Questions / Re: Adafruit Wave shield button press song
|
on: January 29, 2013, 10:47:46 am
|
thanks for the suggestion, PaulS. I have revised my loop as follows: void loop() { buttonState = digitalRead(buttonPin);
// play(root);
root.rewind(); play(root);
while(wave.isplaying){ buttonState = digitalRead(buttonPin); if(buttonState==HIGH){ wave.pause(); digitalWrite(ledPin, HIGH); Serial.println("HIGH"); } else{ wave.resume(); digitalWrite(ledPin, LOW); Serial.println("LOW"); } }
}
It seems the while loop is never gone into. The serial messages are never printed.
|
|
|
|
|
15
|
Using Arduino / Programming Questions / Re: Adafruit Wave shield button press song
|
on: January 29, 2013, 10:27:03 am
|
Thanks guys. the wave pause has been uncommented, moved, and adjusted every which way and I can't find a working solution. Where do you read the switch state? Where do you care about the switch state? am I not doing this with, "buttonState = digitalRead(buttonPin);" ?
|
|
|
|
|