1

Тема: TDA7317

Данный контент доступен только зарегистрированным пользователям.

TDA7317.h

// liman324@yandex.ru rcl-radio.ru


#ifndef TDA7317_H
#define TDA7317_H


#define TDA7317_address 0x43 // 18 вывод ADDR не замкнут на землю

#include <Arduino.h>
class TDA7317
{
  public:
    TDA7317();
        void setVolume(int vol);        // 0...47   
        void setBand(int band, int db); // 0...4 (1...5 полоса) , -7...+7 (-14...+14 дБ)
	
  private:
	void writeWire(char a);
};
	
#endif //TDA7317_H

TDA7317.cpp

#include <Arduino.h>
#include <Wire.h>
#include "TDA7317.h"

TDA7317::TDA7317(){
	Wire.begin();
}

void TDA7317::setVolume(int vol){
  vol = 47 - vol;
  writeWire(vol);
}

void TDA7317::setBand(int band, int db){
  switch(band){
     case 0: band = 0b10000000; break;
     case 1: band = 0b10010000; break;
     case 2: band = 0b10100000; break;
     case 3: band = 0b10110000; break;
     case 4: band = 0b11000000; break;
  }
  switch(db){
     case -0: db = 0b00001000; break;
     case -1: db = 0b00001001; break;
     case -2: db = 0b00001010; break;
     case -3: db = 0b00001011; break;
     case -4: db = 0b00001100; break;
     case -5: db = 0b00001101; break;
     case -6: db = 0b00001110; break;
     case -7: db = 0b00001111; break;

     case 1: db = 0b00000001; break;
     case 2: db = 0b00000010; break;
     case 3: db = 0b00000011; break;
     case 4: db = 0b00000100; break;
     case 5: db = 0b00000101; break;
     case 6: db = 0b00000110; break;
     case 7: db = 0b00000111; break;
  }
    int ekv = band + db;
    writeWire(ekv);
}


void TDA7317::writeWire(char a){
  Wire.beginTransmission(TDA7317_address);
  Wire.write (a);
  Wire.endTransmission();
}

TDA7317.ino

#include <Wire.h>
#include <TDA7317.h>
  TDA7317 tda;
  
void setup(){ 
  Serial.begin(9600);Wire.begin();
  audio();
}

void loop(){}

void audio(){
  tda.setVolume(35); // громкость 0...47
  /////////// номер полосы, дБ (-7...+7) //////////
  tda.setBand(0,0);  // 10000 Hz
  tda.setBand(1,0);  // 260   Hz
  tda.setBand(2,0);  // 1000  Hz
  tda.setBand(3,0);  // 3000  Hz
  tda.setBand(4,0);  // 60    Hz
}