Hallo Allemaal
Hieronder een foto en routine voor tekenen
pelorus op nokia LCD 5110 met AdaFruit libs
Dus alle zelfbouwers en knutselaars
die zelf een arduino doppler willen maken eigen design.
De functie Format3Degrees maakt van bv 22 022
dus 3 digits...
De functie pelorus roep je gewoon aan met Pelorus(270)
in de Loop oid..
Dit programma geeft random graden weer
Ik gebruik 999 als reset of geen signaal dus geen peil weergeven
maar alleen de circel.
Have fun ...
Code:
/*
* Klooi Pelorus File voor testen enzo PA3BNX met Nokia LCD5110 en Arduino Nano
* 06-07-2018
*/
/*********************************************************************
This is an example sketch for our Monochrome Nokia 5110 LCD Displays
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/products/338
These displays use SPI to communicate, 4 or 5 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, check license.txt for more information
All text above, and the splash screen must be included in any redistribution
*********************************************************************/
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
// Software SPI (slower updates, more flexible pin options):
// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);
// Hardware SPI (faster, but must use certain hardware pins):
// SCK is LCD serial clock (SCLK) - this is pin 13 on Arduino Uno
// MOSI is LCD DIN - this is pin 11 on an Arduino Uno
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
// Adafruit_PCD8544 display = Adafruit_PCD8544(5, 4, 3);
// Note with hardware SPI MISO and SS pins aren't used but will still be read
// and written to during SPI transfer. Be careful sharing these pins!
int t = 200;
void Pelorus(int d){
//Float
const float rad =PI/180 ; //0.017453292
float q;
//Int
static int OldDegrees = 999;
//Integer
int xc = display.width()/2 -1;
int yc = display.height()/2-1;
int r = yc-2;
byte y;
int s,ss;
//Nothing ToDo
if (OldDegrees==d)
{
return;
}
display.clearDisplay();
display.drawCircle(xc,yc,yc,BLACK);
if (d==999)
{
display.fillCircle(xc,yc,2,BLACK); //Just a Center dot now
}
else
{
q = (d-90) * rad;
s = xc + int(cos(q)*r);
ss = yc + int(sin(q)*r);
display.drawLine(xc,yc,s,ss,BLACK);
//Text print
if (d > 270 || d < 90)
{
y=yc+3;
}
else
{
y=yc-10;
}
display.setTextSize(1);
display.setCursor(xc-9,y);
display.println(Format3Degrees(d));
}
display.display();
OldDegrees=d;//Backup now
Serial.println(d);
}
String Format3Degrees(int d){
String str;
int digits[3];
int reminder;
digits[0]=d/100;
reminder=d%100;
digits[1]=reminder/10;
reminder=reminder%10;
digits[2]=reminder;
//str+='%';
str+=digits[0];
str+=digits[1];
str+=digits[2];
return str;
}
void setup(){
Serial.begin(9600);
display.begin();
// init done
// you can change the contrast around to adapt the display
// for the best viewing!
display.setContrast(50);
}
void loop(){
Pelorus(999);
delay(500);
for (int i=0;i<800;i++)
{
Pelorus(random(0,360));
delay(100);
}
delay(250);
}