Michael Spencer / Smoothie

Dependencies:   mbed

Fork of Smoothie by Stéphane Cachat

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AK4183.cpp Source File

AK4183.cpp

00001 /*
00002  * AK4183.cpp
00003  *
00004  *  Created on: 21-06-2013
00005  *      Author: Wulfnor
00006  */
00007 
00008 #include "AK4183.h"
00009 
00010 AK4183::AK4183() {
00011     this->i2c_address = TS_ADDRESS;
00012     this->i2c = new mbed::I2C(p9, p10); // P0_0, P0_1
00013 
00014     i2c->frequency(40000);
00015 
00016     penIRQ.from_string("3.25")->as_input();
00017 }
00018 
00019 AK4183::~AK4183() {
00020     delete this->i2c;
00021 }
00022 
00023 unsigned char AK4183::read_adc(unsigned char cmd){
00024     char data[2];
00025     data[0] = cmd;
00026     i2c->write(this->i2c_address, data, 1);
00027     i2c->read(this->i2c_address, data, 1);       // Read from selected Register
00028     return (~data[0]);
00029 }
00030 
00031 bool AK4183::pen_touching(){
00032     return !penIRQ.get();
00033 }
00034 int AK4183::get_x(){
00035     return read_adc(0xC2);
00036 }
00037 
00038 int AK4183::get_y(){
00039     return read_adc(0xD2);
00040 }