Go Down

Topic: ar1010lib (Read 987 times) previous topic - next topic

Peter S.

Oct 03, 2010, 01:48 am Last Edit: Oct 03, 2010, 01:49 am by pxsloot Reason: 1
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: [Select]

/*
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());
 }
}

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy