Show Posts
|
|
Pages: [1] 2
|
|
2
|
Using Arduino / Programming Questions / Re: Controlling a LCD backlight
|
on: August 31, 2011, 07:52:39 am
|
THANKS! That made me think in a new way, and solved the problem, also tidied the code up a bit.  const int buzzerPin = 2; // Signal from buzzer const int ledPin = 11; // Backlight
int buzzerState = 0; long previousMillis = 0; long full = 8000; //time in ms for full brightness long dim = 12000; /time in ms for dimmed brightness
void setup() { pinMode(ledPin, OUTPUT); pinMode(buzzerPin, INPUT); }
void loop(){ buzzerState = digitalRead(buzzerPin); // read the state of the buzzer: unsigned long currentMillis = millis(); // check if the buzzer is sounded. // if it is, the buzzerState is HIGH: if(buzzerState == HIGH) { previousMillis = currentMillis; } if(currentMillis - previousMillis < full) analogWrite(ledPin, 255); else if(currentMillis - previousMillis < full + dim) analogWrite(ledPin, 200); else analogWrite(ledPin, 0); }
|
|
|
|
|
3
|
Using Arduino / Programming Questions / Controlling a LCD backlight
|
on: August 30, 2011, 05:12:21 pm
|
Hi, I'm in the process of adding backlight for the LCD on my RC-transmitter and had a spare Nano, so I decided to go overkill on the control of it. I have a input from the buzzer on the transmitter, (via a optocoupler) and the plan was to light the backlight everytime it sounded, and after a couple of seconds it would fade to a lower light then turn completely off after a few more seconds. after some tweeking of my second attempt, I got it to actually turn off, but the problem I have is that I want the light to stay on for 4 seconds after the LAST beep, now it is on for 4 (+8 at dim) seconds after the FIRST beep. Can someone please help me? Here is the code: const int buzzerPin = 2; // Signal from buzzer const int ledPin = 11; // Backlight
int buzzerState = 0;
void light(int state){
switch (state){ case 1: // full / half brightness { analogWrite(ledPin, 255); // full brightness on backlight delay(4000); analogWrite(ledPin, 200); // reduced brightness on backlight delay(8000); } case 2: // turn off light { digitalWrite(ledPin, 0); // turn backlight off: } } }
void setup() { pinMode(ledPin, OUTPUT); pinMode(buzzerPin, INPUT); }
void loop(){ // read the state of the buzzer value: buzzerState = digitalRead(buzzerPin);
// check if the buzzer is sounded. // if it is, the buzzerState is HIGH: if (buzzerState == HIGH) { light(1); } else { light(2);
} }
|
|
|
|
|
4
|
Forum 2005-2010 (read only) / Interfacing / Re: Interfacing with four thumbwheel switches.
|
on: November 10, 2009, 06:11:07 pm
|
|
I added a few lines more code, and hooked up my Fluke Scopemeter to the output-pin, and I have adjustable frequency out, it not 100% accurate, but not totally off. when I selected 3000 rpm, i should get 50Hz (50HZ X 60sec = 3000 RPM) But I got 46 Hz instead (2760 rpm). and at 6000 rpm I should get 100Hz, but got 89 instead... small issues, hopefully resolvable..
|
|
|
|
|
6
|
Forum 2005-2010 (read only) / Interfacing / Re: Interfacing with four thumbwheel switches.
|
on: November 08, 2009, 04:23:58 pm
|
Ok, so Ive been away from this project for a while now, and I need help with the next part. I've changed my code a little now so it adds the numbers together and sends one 4-digit number, instead of 4 seperate numbers without space between them over serial, and I added some math to devide the 4-digit input by 60, to get Hz/RPS instead of RPM the next obsticle is to output this frequenzy to pin 13 Here is some code: #include "math.h" int potPin0 = 0; // select the input pin for the potentiometer int potPin1 = 1; int potPin2 = 2; int potPin3 = 3; int val0 = 0; // variable to store the value coming from the sensor int val1 = 0; int val2 = 0; int val3 = 0; int val4 = 0; int val5 = 0; int val6 = 0; int val7 = 0; int setting; int Hz; int ledPin = 13;
void setup() { Serial.begin(9600); // use the serial port to send the values back to the computer } void loop() { val0 = analogRead(potPin0); // read the value from the sensor if (val0 < 2) val4 = 0; else if (val0 < 100) val4 = 1000; else if (val0 < 200) val4 = 2000; else if (val0 < 300) val4 = 3000; else if (val0 < 400) val4 = 4000; else if (val0 < 600) val4 = 5000; else if (val0 < 700) val4 = 6000; else if (val0 < 800) val4 = 7000; else if (val0 < 950) val4 = 8000; else if (val0 > 1000) val4 = 9000; val1 = analogRead(potPin1); // read the value from the sensor if (val1 < 2) val5 = 0; else if (val1 < 100) val5 = 100; else if (val1 < 200) val5 = 200; else if (val1 < 300) val5 = 300; else if (val1 < 400) val5 = 400; else if (val1 < 600) val5 = 500; else if (val1 < 700) val5 = 600; else if (val1 < 800) val5 = 700; else if (val1 < 950) val5 = 800; else if (val1 > 1000) val5 = 900; val2 = analogRead(potPin2); // read the value from the sensor if (val2 < 2) val6 = 0; else if (val2 < 100) val6 = 10; else if (val2 < 200) val6 = 20; else if (val2 < 300) val6 = 30; else if (val2 < 400) val6 = 40; else if (val2 < 600) val6 = 50; else if (val2 < 700) val6 = 60; else if (val2 < 800) val6 = 70; else if (val2 < 950) val6 = 80; else if (val2 > 1000) val6 = 90; val3 = analogRead(potPin3); // read the value from the sensor if (val3 < 2) val7 = 0; else if (val3 < 100) val7 = 1; else if (val3 < 200) val7 = 2; else if (val3 < 300) val7 = 3; else if (val3 < 400) val7 = 4; else if (val3 < 600) val7 = 5; else if (val3 < 700) val7 = 6; else if (val3 < 800) val7 = 7; else if (val3 < 950) val7 = 8; else if (val3 > 1000) val7 = 9; setting = val4 + val5 + val6 + val7; Hz = setting / 60;
digitalWrite(ledPin, HIGH); // set the LED on delay(time); // wait for a second digitalWrite(ledPin, LOW); // set the LED off delay(time); // wait for a second } Help will be rewared with a biscuit, or atleast a picture of one, as it is illegal to ship food internationally.. 
|
|
|
|
|
7
|
Forum 2005-2010 (read only) / Interfacing / Re: Interfacing with four thumbwheel switches.
|
on: September 21, 2009, 05:02:29 pm
|
I used my initial idea with cascading diodes and using 4 analog inputs (my first adventure in analog) and i read the value perfectly  now I have to find a way to use the input, for now i just send the value over the serial port so that i can read it in the serial monitor. Code: int potPin0 = 0; // select the input pin for the potentiometer int potPin1 = 1; int potPin2 = 2; int potPin3 = 3; int val0 = 0; // variable to store the value coming from the sensor int val1 = 0; int val2 = 0; int val3 = 0;
void setup() { Serial.begin(9600); // use the serial port to send the values back to the computer } void loop() { val0 = analogRead(potPin0); // read the value from the sensor if (val0 < 2) Serial.print('0'); else if (val0 < 100) Serial.print('1'); else if (val0 < 200) Serial.print('2'); else if (val0 < 300) Serial.print('3'); else if (val0 < 400) Serial.print('4'); else if (val0 < 600) Serial.print('5'); else if (val0 < 700) Serial.print('6'); else if (val0 < 800) Serial.print('7'); else if (val0 < 950) Serial.print('8'); else if (val0 > 1000) Serial.print('9'); val1 = analogRead(potPin1); // read the value from the sensor if (val1 < 2) Serial.print('0'); else if (val1 < 100) Serial.print('1'); else if (val1 < 200) Serial.print('2'); else if (val1 < 300) Serial.print('3'); else if (val1 < 400) Serial.print('4'); else if (val1 < 600) Serial.print('5'); else if (val1 < 700) Serial.print('6'); else if (val1 < 800) Serial.print('7'); else if (val1 < 950) Serial.print('8'); else if (val1 > 1000) Serial.print('9'); val2 = analogRead(potPin2); // read the value from the sensor if (val2 < 2) Serial.print('0'); else if (val2 < 100) Serial.print('1'); else if (val2 < 200) Serial.print('2'); else if (val2 < 300) Serial.print('3'); else if (val2 < 400) Serial.print('4'); else if (val2 < 600) Serial.print('5'); else if (val2 < 700) Serial.print('6'); else if (val2 < 800) Serial.print('7'); else if (val2 < 950) Serial.print('8'); else if (val2 > 1000) Serial.print('9'); val3 = analogRead(potPin3); // read the value from the sensor if (val3 < 2) Serial.print('0'); else if (val3 < 100) Serial.print('1'); else if (val3 < 200) Serial.print('2'); else if (val3 < 300) Serial.print('3'); else if (val3 < 400) Serial.print('4'); else if (val3 < 600) Serial.print('5'); else if (val3 < 700) Serial.print('6'); else if (val3 < 800) Serial.print('7'); else if (val3 < 950) Serial.print('8'); else if (val3 > 1000) Serial.print('9'); Serial.print(" RPM. "); delay(1000); } Pics:   as you can see, only 4 analog pins in use  and a printscreen, showing the same result in the serial monitor as on the thumbwheels  : 
|
|
|
|
|
9
|
Forum 2005-2010 (read only) / Interfacing / Interfacing with four thumbwheel switches.
|
on: September 20, 2009, 09:01:25 am
|
Hi I have a project that involves four thumbwheel switches, to control the frequenzy to shut and poen a pair of old 3D glasses that is basically two large one-pixel LCD screens. this setup will take the numbers (RPM) entered on the thumbwheels and divide it by 60 (seconds) to send the frequnezy (RPM/60) to the glasses, so that I can look at rotating parts as if they are standing still... or figure out the RPMs by adjusting the tumblewheels until the rotating stuff is standing still.  problem is that the thumbwheels PDF! is a decimal type (what i had in my parts-bin) and each switch has outputs for 0-9 and a common. the question is, how do I connect them. I have a couple of ideas, 1: setting them up with one outout for each of the wheels, and 10 inputs, and let the arduino scan the switches. this method needs 14 IO-pins, so there is no pins avaliable for the rest. 2: Shift registers, needs 40 inputs / 8 inputs on each register = 5 chips 3: a combination of 1 and 2. 4. connecting the common on each of the switches to a analog input, and a cascade of diodes to reduce the voltage to each number on the switch, so that, 9=5V, 8=4,4V, 7=3,8v etc. and connect 0 to gnd and somehow decode the analog signal to numbers in arduino. what would you do?
|
|
|
|
|
11
|
Forum 2005-2010 (read only) / Interfacing / Re: Seeed Studio RFID reader
|
on: July 31, 2009, 06:44:08 am
|
OK, starting to get the hang of the programming. my code is mainly based of THIS with some modifications, his tags were 10-bit, mine are 12-bit, he opened a lock, I have to know the difference between the 6 tags in my system. I think I need some help with some new issues that have emerged: if I read a tag, it shows up in the serial monitor as a bad tag, and has a square added after the tag-ID (empty bit?) if i read the next tag, it still says bad tag, and keeps the same tagID as the first tag read. I have to reset the arduino for each tag it reads... :-/ the code: //RFID Clothes Dryer
#include <SoftwareSerial.h> #define rxPin 2 #define txPin 3
SoftwareSerial mySerial= SoftwareSerial(rxPin, txPin); int buzzPin = 5; //buzzer int led1Pin = 6; //user 1 int led2Pin = 7; //user 2 int led3Pin = 8; //user 3 int led4Pin = 9; //user 4 int doorPin = 12; //doorswitch int startPin = 13; //start connected to pin 13 boolean open = true; // default start up is to assume the lock is open int val = 0; char code[12]; int bytesread = 0; int pulse, switchVal; //RFID tags char tag1[13] = "390051A9ED2C"; //user1 char tag2[13] = "39003A80D457"; //user2 char tag3[13] = "3900315FECBB"; //user3 char tag4[13] = "390031587D2D"; //user4 char tag5[13] = "24004D4AF5D6"; //delete char tag6[13] = "24004D31174F"; //read void beep(int state){
switch (state){ case 1: //long beep, bad tag for (long i = 0; i < 2048 * 1; i++ ) { digitalWrite(buzzPin, HIGH); delayMicroseconds(244); digitalWrite(buzzPin, LOW); delayMicroseconds(244); } break; case 2: //short beep, good tag for (long i = 0; i < 1024 * 1; i++ ) { digitalWrite(buzzPin, HIGH); delayMicroseconds(122); digitalWrite(buzzPin, LOW); delayMicroseconds(122); } } } void setup() { Serial.begin(9600); mySerial.begin(9600); pinMode(rxPin, INPUT); pinMode(txPin, OUTPUT); pinMode (buzzPin, OUTPUT); pinMode (led1Pin, OUTPUT); pinMode (led2Pin, OUTPUT); pinMode (led3Pin, OUTPUT); pinMode (led4Pin, OUTPUT); pinMode (doorPin, INPUT); pinMode (startPin, OUTPUT); } boolean checkTag(char *tag){
for (int x=0;x<12;x++){ if( tag[x] != code[x]){ return false; } } return true; }
boolean findGoodTag(){ if (checkTag(tag1)){ return true;} else if (checkTag(tag2)){ return true;} else if (checkTag(tag3)){ return true;} else if (checkTag(tag4)){ return true;} else if (checkTag(tag5)){ return true;} else if (checkTag(tag6)){ return true;}
else{ Serial.print("Bad tag: "); Serial.println(code); beep(1); return false;
} }
void loop() { SoftwareSerial RFID = SoftwareSerial(rxPin,txPin); RFID.begin(9600);
if((val = RFID.read()) == 12) bytesread = 0; while(bytesread<12) { // read 12 digit code val = RFID.read(); if((val == 12)||(val == 14)) { // if header or stop bytes before the 10 digit reading break; // stop reading } code[bytesread] = val; // add the digit bytesread++; // ready to read next digit }
if((bytesread == 12) && (findGoodTag())) { // if 12 digit read is complete delay(500);
} }
|
|
|
|
|
12
|
Forum 2005-2010 (read only) / Interfacing / Re: Seeed Studio FRID reader
|
on: July 30, 2009, 05:41:35 pm
|
Changed my wiring a little to match the one used by someone else, and after Iused this code: #include <SoftwareSerial.h> #define rxPin 2 #define txPin 3
SoftwareSerial mySerial= SoftwareSerial(rxPin, txPin);
void setup() { Serial.begin(9600); mySerial.begin(9600); pinMode(rxPin, INPUT); pinMode(txPin, OUTPUT); } void loop() { for (int i=0;i<=13;i++){ Serial.print(mySerial.read(),BYTE); } Serial.println(" <<Card ID"); delay(1000); } the ID of the tag shows up in the serial monitor  now the next task it so make each tag do something 
|
|
|
|
|
14
|
Forum 2005-2010 (read only) / Interfacing / Seeed Studio RFID reader
|
on: July 30, 2009, 04:11:41 pm
|
Hi I tried modifying the code for the parallax RFID-reader test program to work with the Seeed Studio RFID reader This onethis is how the modified code looks like: int val = 0; char code[10]; int bytesread = 0;
void setup() {
Serial.begin(9600); // RFID reader SOUT pin connected to Serial RX pin at 9600bps
}
void loop() { if(Serial.available() > 0) { // if data available from reader if((val = Serial.read()) == 10) { // check for header bytesread = 0; while(bytesread<10) { // read 10 digit code if( Serial.available() > 0) { val = Serial.read(); if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading break; // stop reading } code[bytesread] = val; // add the digit bytesread++; // ready to read next digit } } if(bytesread == 10) { // if 10 digit read is complete Serial.print("TAG code is: "); // possibly a good TAG Serial.println(code); // print the TAG code } bytesread = 0; delay(500); // wait for a second } } }
This does nothing for me, it should print the code in the serial monitor, but it does not, not even the tx led on the arduino-board lights up having no luck with that one, I tried so simplify it even more, to just give a beep in a buzzer connected to pin 3. this turned out to work, so I know my wiring of reader tx, arduino rx is correct, and that the reader is working. the test code is: int val = 0; char code[10]; int bytesread = 0; int buzPin = 3;
void setup() {
pinMode(buzPin, OUTPUT); Serial.begin(9600); // RFID reader SOUT pin connected to Serial RX pin at 9600bps
}
void loop() { if(Serial.available() > 0) { // if data available from reader digitalWrite(buzPin, HIGH); }
} I googled around and can't find anyone that actually has used this RFID reader on a arduino before... anyone with any good ideas?
|
|
|
|
|