Show Posts
|
|
Pages: [1] 2 3 ... 5
|
|
5
|
Using Arduino / Networking, Protocols, and Devices / Serial.write error when sending an array
|
on: January 15, 2013, 02:57:53 am
|
the following code has a compiler error, which I don't quite understand int serialArrayOne[] = {1,2,3,4,5,6,7,8};
void setup() { Serial.begin(9600); }
void loop() { Serial.write(serialArrayOne,8); } error is: sketch_jan15a.cpp: In function ‘void loop()’: sketch_jan15a.cpp:19:32: error: no matching function for call to ‘HardwareSerial::write(int [8], int)’ /usr/share/arduino/hardware/arduino/cores/arduino/HardwareSerial.h:58:20: note: candidates are: virtual size_t HardwareSerial::write(uint8_t) /usr/share/arduino/hardware/arduino/cores/arduino/Print.h:50:20: note: virtual size_t Print::write(const uint8_t*, size_t) /usr/share/arduino/hardware/arduino/cores/arduino/Print.h:49:12: note: size_t Print::write(const char*) The manual says Serial.write(buf, len) buf: an array to send as a series of bytes len: the length of the buffer Anyone care to enlighten me Cheers Kim
|
|
|
|
|
8
|
Using Arduino / Networking, Protocols, and Devices / RS485 issue using SoftwareSerial()
|
on: January 14, 2013, 01:02:48 am
|
Hi I have downloaded Nick Gammon code, but are having some compiling issues. I got it down to 2 errors //#include "WConstants.h" #include <RS485_non_blocking.h> //#include "RS485_protocol.h" #include <SoftwareSerial.h>
const byte ENABLE_PIN = 4; const byte LED_PIN = 13;
SoftwareSerial rs485(2, 3); // receive pin, transmit pin
// callback routines void fWrite (const byte what) { rs485.print (what); } int fAvailable () { return rs485.available (); }
int fRead () { return rs485.read (); }
void setup() { rs485.begin (28800); pinMode (ENABLE_PIN, OUTPUT); // driver output enable pinMode (LED_PIN, OUTPUT); // built-in LED } // end of setup byte old_level = 0;
void loop() {
// read potentiometer byte level = analogRead (0) / 4; // no change? forget it if (level == old_level) return; // assemble message byte msg [] = { 1, // device 1 2, // turn light on level // to what level };
// send to slave digitalWrite (ENABLE_PIN, HIGH); // enable sending sendMsg (fWrite, msg, sizeof msg); digitalWrite (ENABLE_PIN, LOW); // disable sending
// receive response byte buf [10]; byte received = recvMsg (fAvailable, fRead, buf, sizeof buf); digitalWrite (LED_PIN, received == 0); // turn on LED if error // only send once per successful change if (received) old_level = level;
} // end of loop
Errors are: sketch_jan14a.cpp: In function ‘void loop()’: sketch_jan14a.cpp:62:35: error: ‘sendMsg’ was not declared in this scope sketch_jan14a.cpp:67:62: error: ‘recvMsg’ was not declared in this scope But what do I replace the sendMsg with. I have looked through the SoftwareSerial.cpp and .h files but nothing springs to mind Thanks for any suggestions Kim
|
|
|
|
|
12
|
Using Arduino / Programming Questions / trouble with simple IF...ELSE
|
on: December 22, 2012, 03:01:41 pm
|
I can't for the life of me work out why the code below doesn't work. Never gets to the ELSE statement, something keeps changing the "pinstate" back to zero Cheers K void BlinkLED13() { // blinks LED 13 int pinstate; // state of the output pin
if (pinstate == 0) { digitalWrite(ledPin, pinstate); pinstate = 1; delay(100); } else { digitalWrite(ledPin, pinstate); pinstate = 0; delay(100); }
}
|
|
|
|
|
14
|
Using Arduino / Programming Questions / Using i/o via an array
|
on: December 20, 2012, 01:34:56 pm
|
|
I'm trying to get my head around arrays in C.
I can do the following as to assign i/o pins via an array int pins [6] = { 3, 5, 7, 10, 12, 13 }
However, can I assign a name to a pin and then use it in the array
const int Button1 = 3; int pins [6] = { Button1, 5, 7, 10, 12, 13 }
thanks for any clarification
K
|
|
|
|
|