Show Posts
|
|
Pages: 1 ... 4 5 [6] 7 8 ... 10
|
|
81
|
Using Arduino / Programming Questions / Re: working with classes
|
on: January 09, 2013, 01:47:19 pm
|
it doesn't seems to register the header file correctly, but is including it because I get a error of class is redefined if I copy the class to both files. here is what i would expect works: main file: /* HC-SR04 Sensor https://www.dealextreme.com/p/hc-sr04-ultrasonic-sensor-distance-measuring-module-133696 The circuit: * VCC connection of the sensor attached to +5V * GND connection of the sensor attached to ground * TRIG connection of the sensor attached to digital pin 2 * ECHO connection of the sensor attached to digital pin 4 */ #include "doorClass.h" const int trigPin = 2; const int echoPin = 4;
Door myDoor;
void setup() { Serial.begin(9600); //myDoor = new Door(); } void loop() { long duration, inches, cm; // The sensor is triggered by a HIGH pulse of 10 or more microseconds. // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: pinMode(trigPin, OUTPUT); digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); // Read the signal from the sensor: a HIGH pulse whose // duration is the time (in microseconds) from the sending // of the ping to the reception of its echo off of an object. pinMode(echoPin, INPUT); duration = pulseIn(echoPin, HIGH); // convert the time into a distance inches = microsecondsToInches(duration); cm = microsecondsToCentimeters(duration); /* for(int i = 0; i < 11; i++){ Serial.println(inches); inches++; }
for(int i = 0; i < 11; i++){ Serial.println(inches); inches--; } */ Serial.print(inches); Serial.println("in");
delay(300); myDoor.checkState(inches); Serial.print("doorSwing: "); int doorSwings = myDoor.doorSwings(); Serial.println(doorSwings); } long microsecondsToInches(long microseconds) { // According to Parallax's datasheet for the PING))), there are // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per // second). This gives the distance travelled by the ping, outbound // and return, so we divide by 2 to get the distance of the obstacle. // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf return microseconds / 74 / 2; } long microsecondsToCentimeters(long microseconds) { // The speed of sound is 340 m/s or 29 microseconds per centimeter. // The ping travels out and back, so to find the distance of the // object we take half of the distance travelled. return microseconds / 29 / 2; }
doorClass.h: #include "Arduino.h"
class Door { public: boolean opened; int peopleCounter; int doorSwing; void checkState(int inches) { isOpen(inches) ? open() : close(); } int doorSwings(){ return doorSwing; } private: boolean isOpen(int inches) { return !opened && inches < 10; //return true if passes } void open() { Serial.print("opened!"); if(doorSwing % 2 == 0){ opened = true; peopleCounter++; doorSwing++; } } void close() { Serial.print("closed!"); opened = false; doorSwing++; } //Serial.print("doorSwing: ");
};
|
|
|
|
|
82
|
Using Arduino / Programming Questions / Re: working with classes
|
on: January 09, 2013, 01:09:54 pm
|
|
ah, had no idea you needed a semicolon there, weird. Is there a way to put this into a header file to keep it cleaner too?
maybe something like moving all the class files to doorClass.h and then including it: #include "doorClass.h"
this seems to throw same error, that Door doesn't work when I try to put it in a different file. The file is in the same directory as the other one.
|
|
|
|
|
83
|
Using Arduino / Programming Questions / working with classes
|
on: January 09, 2013, 12:34:54 pm
|
Trying to get classes to work, but for some reason I keep getting this error: "Door does not name a type." Any ideas? class Door { public: boolean opened; int peopleCounter; Door() {} void checkState(int inches) { isOpen(inches) ? open() : close(); } private: boolean isOpen(int inches) { return !opened && inches < 10; //return true if passes } void open() { opened = true; peopleCounter++; } void close() { opened = false; } } const int trigPin = 2; const int echoPin = 4;
Door myDoor;
void setup() { Serial.begin(9600); myDoor = new Door(); } void loop() { long duration, inches, cm; // The sensor is triggered by a HIGH pulse of 10 or more microseconds. // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: pinMode(trigPin, OUTPUT); digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); // Read the signal from the sensor: a HIGH pulse whose // duration is the time (in microseconds) from the sending // of the ping to the reception of its echo off of an object. pinMode(echoPin, INPUT); duration = pulseIn(echoPin, HIGH); // convert the time into a distance inches = microsecondsToInches(duration); cm = microsecondsToCentimeters(duration); for(int i = 0; i < 11; i++){ Serial.println(inches); inches++; }
for(int i = 0; i < 11; i++){ Serial.println(inches); inches--; } Serial.print(inches); Serial.print("in, "); Serial.print(cm); Serial.print("cm"); Serial.println(); delay(100); myDoor.checkState(inches); } long microsecondsToInches(long microseconds) { // According to Parallax's datasheet for the PING))), there are // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per // second). This gives the distance travelled by the ping, outbound // and return, so we divide by 2 to get the distance of the obstacle. // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf return microseconds / 74 / 2; } long microsecondsToCentimeters(long microseconds) { // The speed of sound is 340 m/s or 29 microseconds per centimeter. // The ping travels out and back, so to find the distance of the // object we take half of the distance travelled. return microseconds / 29 / 2; }
|
|
|
|
|
84
|
Using Arduino / Microcontrollers / Re: attiny85 serial monitor
|
on: December 22, 2012, 04:13:05 pm
|
The speed of the internal oscillator varies with voltage. Use a lower baud rate to compensate.
seems I'm running at lowest possible (9600): In member function 'void TinyDebugSerial::begin(long int)', inlined from 'void setup()' at rose.cpp:19: /Users/lukasz/Documents/Arduino/hardware/tiny/cores/tiny/TinyDebugSerial.h:694: error: call to 'TinyDebugSerialBadBaud' declared with attribute error: Serial (TinyDebugSerial) supports three baud rates: 9600, 38400, or 115200.
|
|
|
|
|
85
|
Using Arduino / Microcontrollers / Re: attiny85 serial monitor
|
on: December 22, 2012, 12:40:11 pm
|
I just tryed:
Attiny85v @8mHz TinyDebugSerial at 9600 A (fresh) CR2032 No problem with Serial.print() in serial monitor
And with SoftwareSerial Same result, I am able to communicate with the tiny both ways
I am using these Fuses (BOD disabled)
L: E2 H: D7 E: FF
Interesting. I will look into this as well and post what result I get. thanks.
|
|
|
|
|
86
|
Using Arduino / Microcontrollers / Re: attiny85 serial monitor
|
on: December 22, 2012, 12:37:07 pm
|
Like billroy, I'm only speculating but I'm not sure VCC versus clock speed will be it. My power source of choice for ATTiny85 projects is a single CR2032 and I've never had an issue with them operating at 8MHz (I always burn that speed too). Though to be fair, I'm not doing serial comms in anything I'm referring to here.
Perhaps it's worth consulting the data sheet to see also what voltage the ATTiny is producing for a HIGH signal at 3V. You might just find you've gone below where the Uno reads a HIGH, so your serial comms have become a stream of zeroes to the receiving side.
Cheers ! Geoff
I have no problems running the chip, it really only has to do with serial output. I've gotten it to even output "PWN" (software on a few pins) on 5 pins, so it seems like it's pushing it hard. But I will check out the datasheet, I didn't think to check if it's outputting enough power for HIGH on arduino.
|
|
|
|
|
88
|
Using Arduino / Microcontrollers / attiny85 serial monitor
|
on: December 22, 2012, 01:08:08 am
|
|
I have the monitor working well and everything but some oddities are happening when I try external power. I seem to be able to get readings on serial monitor in IDE when I have it plugged into 3.3v on ardiuno board, but when I try 3v battery (CR2032) it doesn't seem to want to read serial, all I do is disconnect the power and plug in the battery instead, so Tx is still connected to arduino and obviously still connected to USB.
does it need a certain voltage for serial? attiny85 specs say it's rated 2.7 V ~ 5.5 V so I am a bit confused.
|
|
|
|
|
89
|
Topics / Device Hacking / Re: Problems with MindFlex Hack
|
on: December 11, 2012, 02:52:23 pm
|
|
this should be on the processing forum, since it's more of a processing problem than arduino. However, I have successfully done this hack with processing 2.0b6. try downloading controlP5 again and delete old version, you might have some legacy items in there.
|
|
|
|
|
90
|
Using Arduino / Microcontrollers / Re: capacitive switch on attiny85
|
on: November 30, 2012, 11:33:04 pm
|
|
yeah, easy with arduino, just having issues with how to implement it with attiny85. just not sure if I need hardware or if I should go software route to turn the program on. or if there is even a cap sense lib for attiny85
|
|
|
|
|