Basic Component Libraries

Hello fellow arduinoers, I've just spent my day teaching the magic of arduino to some of my friends.

I realized that for non programmers, such as my artist brother, it is not intuitive to write digitalRead to find if a switch is either on / off, or use digitalWrite several times to make sounds, so, I wrote a few libraries that handles the four basic components I thought a beginner normaly uses.

These include:
LED
Pot
Switch
Summer

Download from http://home.nith.no/~breale/Arduino/
They are packaged in .rar and is to be extracted in the libraries folder.

LED

  LED(uint8_t pin);
  bool getState();
  void on();
  void off();
  void toggle();
  void setValue(unsigned short val);
  void fadeIn(unsigned int time);
  void fadeOut(unsigned int time);

Pot

  Pot(uint8_t pin);
  Pot(uint8_t pin, uint sectors);
  uint getValue();
  uint getSector();
  void setSectors(uint sectors);

Switch

  Switch(uint8_t pin);
  void setHigh();
  bool getState();

Summer

  Summer(uint8_t pin);
  void setTone(unsigned short tone);
  void setTempo(unsigned int tempo);
  void beep(unsigned int toneFrequency);
  void playTone(unsigned int toneFrequency, unsigned short beats);

Smart idea, alphabeta! Thanks for sharing.

Mikal

@mikalhart: thanks for the compliment :slight_smile:

This is the library equivalent to the wellknown 'Digital->Blink'

#include <LED.h>

//create a LED object at digital pin 13
LED led(13);

void setup(){
  //your setup routine here
}

void loop(){

  //turn led on
  led.on();

  delay(1000); //wait to let us see the change

  //turn led off
  led.off();

  delay(1000); //wait to let us see the change
}

I would greatly appreciate ideas on further functions or classes, and of course bug reports.