Pages: [1]   Go Down
Author Topic: ar1010lib  (Read 770 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Got the ar1010lib by Adam Jansch working http://research.adamjansch.co.uk/code/ar1010-library/. Couldn't find any reference or example code, so here is mine:

Code:
/*
ar1010 -> arduino:
  DATA -> ANALOG IN 4 (Arduino)
  CLK -> ANALOG IN 5 (Arduino)
  CS -> NONE
  ROUT -> RSH (3.5 Jack)
  LOUT -> TSH (3.5 Jack)
  GND -> GND (Arduino)
  VCC -> 3V3 (Arduino)
  GND (3.5 Jack) -> GND (Arduino)

I added a button (pin 2 == interrupt 0) and a LED on pin 12.

(code is crude and has debug statements, it's late)
*/

#include <Wire.h>
#include <ar1010lib.h>

const byte BUTTON = 0;

AR1010 radio = AR1010();

double freq = 1021;
volatile int button_state = LOW;
int old_button_state = LOW;

void buttonPressed() {
//  Serial.println("button pressed");
//  digitalWrite(12, HIGH);
  button_state = !button_state;
  delay(50);
//  digitalWrite(12, LOW);
}

void setup() {
  Wire.begin();
  Serial.begin(9600);
  radio.initialise();
  radio.setFrequency(freq);
  radio.setVolume(15);

  pinMode(12, OUTPUT);
  attachInterrupt(BUTTON, buttonPressed, RISING);
  
  Serial.println("Started up");
}

void loop() {
  if (button_state != old_button_state) {
    // 2 radio stations
    freq = ( freq == 968 ) ? 1021 : 968;
    Serial.print("freq = ");
    Serial.print(freq);
    old_button_state = button_state;
    radio.setFrequency(freq);
    //radio.seek("u");

    delay(100);
    Serial.print(" - ");
    Serial.println(radio.frequency());
  }
}
« Last Edit: October 02, 2010, 06:49:12 pm by pxsloot » Logged

Pages: [1]   Go Up
Jump to: