(6.5) POT와 SPDT 제어
ScanDriver.h
#ifndef SHIFT_H
#define SHIFT_H
#include "wiringPi.h"
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "wiringPiSPI.h"
#define SPI_CHANNEL 0
#define SPI_SPEED 100000
#define CS 0
#define VOLT0 0
#define VOLT20 1
#define VOLTM20 2
//pin
#define SPDT_0 21 //5
#define SPDT_1 22 //6
#define PROGRAMR_2 26//12
#define PROGRAMR_3 6//25
void init_scanDriver(void);
void digitalPotWrite(unsigned char data);
void centerOfObservation(int x, int y);
void y_Shift(int y);
void x_Shift(int x);
void SPDT_cont(int type);
void ProgramR2_cont(int bigScaleVal);
void ProgramR3_cont(int smallScaleVal);
#endif // SHIFT_H
|
scanDriver.cpp
#include "scanDriver.h"
void init_scanDriver(void){
wiringPiSetup();
wiringPiSPISetup(SPI_CHANNEL, SPI_SPEED);
//pinMode(CS, OUTPUT);
pinMode(SPDT_0, OUTPUT);
pinMode(SPDT_1, OUTPUT);
pinMode(PROGRAMR_2 , OUTPUT);
pinMode(PROGRAMR_3 , OUTPUT);
}
void digitalPotWrite(int PROGRAMR, unsigned char data)
{
unsigned char address = 0x11;
digitalWrite(PROGRAMR, LOW);
wiringPiSPIDataRW(SPI_CHANNEL, &address, 1);
wiringPiSPIDataRW(SPI_CHANNEL, &data, 1);
digitalWrite(PROGRAMR, HIGH);
}
void centerOfObservation(int x, int y){
x_Shift(x);
//y_Shift(y);
}
void x_Shift(int x){
if(x == 0){
SPDT_cont(VOLT0);
return;
}
else if(x>0){
SPDT_cont(VOLT20);
}
else if(x<0){
SPDT_cont(VOLTM20); //minus 20 voltage
x=-1*x;
}
ProgramR2_cont(x/200); //big scale
ProgramR3_cont(x%200); //small scale
}
void SPDT_cont(int type){
if(type == VOLT0){
digitalWrite(SPDT_0, LOW);
digitalWrite(SPDT_1, LOW);
}else if(type == VOLT20){
digitalWrite(SPDT_0, HIGH);
digitalWrite(SPDT_1, LOW);
}else if(type == VOLTM20){
digitalWrite(SPDT_0, HIGH);
digitalWrite(SPDT_1, HIGH);
}
}
void ProgramR2_cont(int bigScaleVal){
if(bigScaleVal > 99)
bigScaleVal = 99;
else if(bigScaleVal < 0){
printf("big scale value is minus. error!!\n");
return;
}
digitalPotWrite(PROGRAMR_2 ,bigScaleVal);
}
void ProgramR3_cont(int smallScaleVal){
if(smallScaleVal > 199)
smallScaleVal = 199;
else if(smallScaleVal < 0){
printf("small scale value is minus, error\n");
return;
}
digitalPotWrite(PROGRAMR_3, smallScaleVal);
}
|
댓글 없음:
댓글 쓰기