|
5719
|
Topics / Robotics / Re: timing a movement for a watch winder
|
on: May 16, 2011, 09:11:55 am
|
#include <Servo.h> Servo myservo; int pos = 0; void setup() { } void loop() { for (int i=0; i<10; i++) { myservo.write(100); // Pre-set the motor speed myservo.attach(9); // Attach the servo to start the motor spinning delay(30L*60L*1000L); // Wait 30 minutes myservo.write(92); // Set the motor speed to zero (between forward and backward) myservo.detach(); // Stop sending pulses to the servo delay(15L*60L*1000L); // Wait for 15 minutes before running again } delay(990L*60L*1000L); // Wait for 990 minutes }
|
|
|
|
|
5720
|
Using Arduino / Storage / Re: Read txt file into array from SD
|
on: May 16, 2011, 08:59:10 am
|
I thought the code was 14 characters because that's how many you were copying. For a 12-character code: const int IDLEN = 12; const int NAMELEN = 27;
char currline[IDLEN + 1 + NAMELEN]; // ID, plus comma, plus Name char id[IDLEN+1]; // ID plus a null terminator char name[NAMELEN + 1]; // Name plus a null terminator
while (sdin.getline(currline, sizeof currline, '\n')) { char *line = currline; int i;
for (i=0; i < IDLEN; i++) id[i] = *line++; id[i] = '\0'; // Make it a valid string by adding a terminator.
line++; // Skip the comma in the line for (int 1=0; i < NAMELEN; i++) name[i] = *line++; name[i] = '\0'; // Make it a valid string by adding a terminator
[/quote]
|
|
|
|
|
5723
|
Topics / Robotics / Re: timing a movement for a watch winder
|
on: May 15, 2011, 08:44:01 pm
|
|
void loop() { for (int i=0; i<10; i++) { startMotion(); delay(30L*60L*1000L); // 30 seconds stopMotion(); delay(15L*60L*1000L); // 15 seconds } delay(990L*60L*1000L); // 990 seconds }
|
|
|
|
|
5724
|
Using Arduino / Microcontrollers / Re: Looking for the right document(s)
|
on: May 15, 2011, 08:37:55 pm
|
|
It is a bit confusing but when you pass pin numbers to pinMode, digitalRead, digitalWrite, or analogWrite, the value is the Arduino digital pin number. You find them printed on the Arduino board. The analogRead function uses the Arduino analog input pin numbers (0-5 for most, 0-7 for the Nano). The analog input pins can also be used as digital pins: analog inputs 0..7 are also known as digital pins 14..21.
If you want to use direct port access you can find look-up tables that show the mapping from port and bit to Arduino pin. You can also look at the schematic for your board.
|
|
|
|
|
5726
|
Using Arduino / Motors, Mechanics, and Power / Re: Arduino beating up my servos
|
on: May 15, 2011, 07:17:07 pm
|
|
I wonder if something damaged the crystal and you're getting the wrong clock speed. I would not think so because the serial baud rate would be off b the same amount and uploads would stop working. Are you sure you didn't add anything to your code around the time of the accident?
Try some of the servo example sketches to see if they behave normally. If so, it's your code.
|
|
|
|
|
5727
|
Using Arduino / Microcontrollers / Re: Blink on AtTiny85
|
on: May 15, 2011, 07:12:39 pm
|
|
If Pin 0 is used for serial I/O like on a regular Arduino that might cause some voltage to seep into the LED. Did you disconnect from the serial port after uploading the sketch?
|
|
|
|
|
5728
|
Using Arduino / Programming Questions / Re: Serial Monitor
|
on: May 15, 2011, 07:06:57 pm
|
Serial.read() does not wait for input. This is how you wait: while(!Serial.available()) /* DO NOTHING */; // Wait for a character to be availble char input = Serial.read();
or
int input; while ((input = Serial.read()) == -1) /*KEEP TRYING*/; // Read until we don't get -1 (=no data available)
|
|
|
|
|
5730
|
Using Arduino / Storage / Re: Read txt file into array from SD
|
on: May 15, 2011, 06:52:00 pm
|
You forgot to add a null terminator at the end of the ID. The println() function takes a character pointer and prints characters until it gets to a null character. You are also moving 14 characters (0..13) into an array sized for 13. Bad move. Change ID (and name) to contain one more character than you copy. char currline[40]; char id[15]; // 14 characters plus a null terminator
while (sdin.getline(currline, 40, '\n')) { char name[40-15+1]; char *line = currline; int i;
for (i=0; i < 14; i++) id[i] = *line++; id[i] = '\0'; // Make it a valid string by adding a terminator.
line++; // Skip the comma in the line for (int 1=0; i < sizeof name; i++) name[i] = *line++; name[i] = '\0'; // Make it a valid string by adding a terminator
if (!myFile.open("CLASS.TXT", O_WRITE | O_CREAT | O_APPEND)) { sd.errorHalt(); } // if the file opened okay, write to it: myFile.println(name); myFile.println(id); myFile.close();
}
sdin.close();
|
|
|
|
|