hittade minnepinnen...
nedan för att styra en ds1267 från gaspedalen eller en potte på labbplattan...
kanske lite intetsägande utan schema på kopplingen, men du får den iaf..
för hur man kopplar går att klura ut, om inte finns exempel på nätet...
kopplade in en display för att kunna se ut-värdet i form av en stapel...
Kod: Markera allt
/*
LiquidCrystal Library - Hello World
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
library works with all LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.
This sketch prints "Hello World!" to the LCD
and shows the time.
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/LiquidCrystal
*/
// include the library code:
#include <LiquidCrystal.h>
int trottlePin = A0;
int PotRST = 10;
int PotCLK = 9;
int PotDQ = 8;
unsigned char pot0 = 0;
unsigned char pot1 = 0;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(6, 7, 2, 3, 4, 5);
void setup() {
pinMode(PotRST, OUTPUT);
pinMode(PotCLK, OUTPUT);
pinMode(PotDQ, OUTPUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
//lcd.print("hello, world!");
//WritePot(256, 256);
}
void loop(){
float voltage1;
char outBuf[8] = "";
int b;
int trottle = (analogRead(trottlePin))/3.2;
if( trottle < 255)
{
pot0 = trottle;
pot1 = trottle;
}
else
{
pot0 = 255;
pot1 = 255;
}
WritePot();
String myString = String (trottle);
/* lcd.setCursor(0, 1);
for( b = 0; b < (3-myString.length()); b++ )
{
lcd.print('0');
}
lcd.print( myString );*/
int maxValue = (trottle/16)+1;
lcd.setCursor(0, 0);
lcd.print( char(255) );
for( b = 1; b < 16; b++)
{
lcd.setCursor(b, 0);
if( b < maxValue )
{
lcd.print( char(255) );
}
else
{
lcd.print( " " );
}
}
}
void WritePot() // write pot value to display as a bar
{
unsigned char i,pot0Shifted,pot1Shifted;
digitalWrite(PotRST, HIGH);
digitalWrite(PotDQ, HIGH);
digitalWrite(PotCLK, HIGH);
digitalWrite(PotCLK, LOW);
//pot0 = 64;
//pot1 = 64;
pot0Shifted = pot0;
pot1Shifted = pot1;
for (i = 1; i < 9; i++)
{
if( (pot1Shifted & B10000000) == B10000000 )
{
digitalWrite(PotDQ, HIGH);
}
else
{
digitalWrite(PotDQ, LOW);
}
digitalWrite(PotCLK, HIGH);
digitalWrite(PotCLK, LOW);
pot1Shifted = (pot1 << i);
/* lcd.setCursor(0, 1);
String myString = String ((pot1Shifted & B00000001));
if( i == 5 )
{
lcd.print( myString );
}*/
//delay(1000);
}
for (i = 1; i < 9; i++)
{
if( (pot0Shifted & B10000000) == B10000000 )
{
digitalWrite(PotDQ, HIGH);
}
else
{
digitalWrite(PotDQ, LOW);
}
digitalWrite(PotCLK, HIGH);
digitalWrite(PotCLK, LOW);
pot0Shifted = (pot0 << i);
}
digitalWrite(PotRST, LOW);
}