Tell us about yourself!

Complete Your Profile
  • NicS8 commented on tttapa's instructable A beginner's guide to Arduino3 years ago
    A beginner's guide to Arduino

    Actually the "Arduino" language isn't "C-like", it's C++ which will accept ANSI C code with a little more strictness with prototyping and typing. The underlying compiler is GNU C++. (g++) however standard libraries are not there or some functions are severely limited (for example the printf functions do not work with floating point)Perhaps this is beyond the scope of a beginner's article, but, full C++ classes can be defined and use, so, for example, you could define a class such as: -- Code -- class digIO {private:int pin;int state;int value;public:digIO(pin, initstate = LOW) {this->pin = pin;this->state = initstate;}void poll(void) {pinMode(this->pin,INPUT);this->value = digitalRead(pin);}int get(void) {return this->value;}int set(int value) {this-&g...

    see more »

    Actually the "Arduino" language isn't "C-like", it's C++ which will accept ANSI C code with a little more strictness with prototyping and typing. The underlying compiler is GNU C++. (g++) however standard libraries are not there or some functions are severely limited (for example the printf functions do not work with floating point)Perhaps this is beyond the scope of a beginner's article, but, full C++ classes can be defined and use, so, for example, you could define a class such as: -- Code -- class digIO {private:int pin;int state;int value;public:digIO(pin, initstate = LOW) {this->pin = pin;this->state = initstate;}void poll(void) {pinMode(this->pin,INPUT);this->value = digitalRead(pin);}int get(void) {return this->value;}int set(int value) {this->value = (value == HIGH) ? HIGH : LOW;pinMode(this->pin,OUTPUT);digitalWrite(this->pin,this->value);}};then the code could use: digIO pin1(1);the poll method could be called in the loop function, or manually. The value that was last set (via the set method) or polled can be retrieved with the get method. The compiler generates nice tight code too!

    Actually the "Arduino" language isn't C, it's C++ which will accept ANSI C code with a little more strictness with prototyping and typing. The underlying compiler is GNU C++. (g++) however standard libraries are not there or some functions are severely limited (for example the printf functions do not work with floating point)Perhaps this is beyond the scope of a beginner's article, but, full C++ classes can be defined and use, so, for example, you could define a class such as: -- Code -- class digIO {private:int pin;int state;int value;public:digIO(pin, initstate = LOW) {this->pin = pin;this->state = initstate;}void poll(void) {pinMode(this->pin,INPUT);this->value = digitalRead(pin);}int get(void) {return this->value;}int set(int value) { this->value = (value...

    see more »

    Actually the "Arduino" language isn't C, it's C++ which will accept ANSI C code with a little more strictness with prototyping and typing. The underlying compiler is GNU C++. (g++) however standard libraries are not there or some functions are severely limited (for example the printf functions do not work with floating point)Perhaps this is beyond the scope of a beginner's article, but, full C++ classes can be defined and use, so, for example, you could define a class such as: -- Code -- class digIO {private:int pin;int state;int value;public:digIO(pin, initstate = LOW) {this->pin = pin;this->state = initstate;}void poll(void) {pinMode(this->pin,INPUT);this->value = digitalRead(pin);}int get(void) {return this->value;}int set(int value) { this->value = (value == HIGH) ? HIGH : LOW;pinMode(this->pin,OUTPUT);digitalWrite(this->pin,this->value);}};then the code could use: digIO pin1(1); the poll method could be called in the loop function, or manually. The value that was last set (via the set method) or polled can be retrieved with the get method. The compiler generates nice tight code too!

    View Instructable »