Skip to content

Instantly share code, notes, and snippets.

@ti-nspire
Last active January 18, 2020 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ti-nspire/f219dbe5f07fd0b840f7e84b4bd842ba to your computer and use it in GitHub Desktop.
Save ti-nspire/f219dbe5f07fd0b840f7e84b4bd842ba to your computer and use it in GitHub Desktop.
AD8402_library_for_ATmega328P
#include <avr/io.h>
#include "AD8402.h"
#include "mySPIv2.h"
void AD8402::setChPos(uint8_t ch, uint8_t pos){
mySPI.selectSlave(_port, _pin);
mySPI.tradeByte(ch - 1);
mySPI.tradeByte(pos);
mySPI.deselectSlave(_port, _pin);
switch(ch){
case 1 : _posOfCh1 = pos; break;
case 2 : _posOfCh2 = pos; break;
default: break;
}
}
uint8_t AD8402::getPort(){return _port;}
uint8_t AD8402::getPin (){return _pin;}
uint8_t AD8402::getPosOfCh(uint8_t ch){
switch(ch){
case 1 : return _posOfCh1; break;
case 2 : return _posOfCh2; break;
default: break;
}
}
// コンストラクター
AD8402::AD8402(uint8_t port, uint8_t pin){
_port = port;
_pin = pin;
mySPI.setPins(_port, _pin);
}
//#include <avr/io.h>
#include "mySPIv2.h"
#ifndef AD8402_H
#define AD8402_H
class AD8402{
private:
uint8_t _port;
uint8_t _pin;
uint8_t _posOfCh1;
uint8_t _posOfCh2;
public:
void setChPos(uint8_t ch, uint8_t pos);
uint8_t getPort();
uint8_t getPin();
uint8_t getPosOfCh(uint8_t ch);
// コンストラクター。PB3、PB4、PB5は指定しないこと。
AD8402(uint8_t port, uint8_t pin);
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment