Raymond Goossens
Meten is weten en proberen is leren!
Hallo allemaal
ik ben bezig met het c programmeren van het nanoboard 3000. Nu heb ik zelf al de applicatie geschreven om een sensor uit te lezen, de LM75. Echter wil ik nu de temperatuur die uit de sensor komt gaan vergelijken met een ingestelde waarde. Dit is ook al voor een deel gelukt. De laatste uitbreiding die ik nog wil doen is dat ik door middel van het touchscreen op het nanoboard 3000 van altium de ingestelde waarde wil varieren. Ik heb hiervoor een voorbeeld file gevonden maar kom daar niet echt uit. Hieronder volgt eerst het nu werkende programma voor de sensor.Bij dit programma zijn al twee rechthoeken aangemaakt in het canvas. Weet iemand misschien hoe ik deze kan gaan gebruiken als daadwerkelijke toetsen? Het voorbeeld file wat ik had gevonden heb ik hieronder in een reactie geplakt. Daardoor zijn de twee goed te scheiden
#include <devices.h>
#include <graphics.h>
#include <drv_pwmx.h>
#include <stdio.h>
#include <timing.h>
#include <drv_i2cm.h>
#include <touchscreen.h>
void set_temp(void);
void print_temp(void);
void init_disp_pwm(void);
void read_from_sensor(void);
i2cm_t * i2c;
graphics_t* graphics;
canvas_t *canvas;
int temp_instel = 25, temp_val;
char temp[40], instel[40], probeer;
void read_from_sensor(void)
{
i2c = i2cm_open(DRV_I2CM_1);
i2cm_putchar(i2c, true, 0x91);
probeer = i2cm_getchar(i2c,false,false);
i2cm_putchar(i2c, false, 0);
i2cm_stop(i2c);
i2cm_release_bus(i2c);
}
void init_disp_pwm (void)
{
pwmx_t* pwm;
pwm = pwmx_open(DRV_PWMX_1);
graphics = graphics_open(GRAPHICS_1);
canvas = graphics_get_visible_canvas(graphics);
pwmx_set_resolution_mode(pwm, PWMX_MODE_8BIT);
pwmx_set_frequency(pwm, 10000);
pwmx_enable_controller(pwm);
pwmx_set_pulsewidth(pwm, 0xFF);
}
void set_temp (void)
{
temp_val = probeer;
if (temp_val & 0x0100)
temp_val |= 0xFE00;
sprintf(temp, "Temperatuur: %3d deg C.", temp_val);
sprintf(instel, "Gewenste temp: %3d deg C.", temp_instel);
}
void print_temp (void)
{
graphics_fill_canvas(canvas, WHITE);
graphics_fill_rect(canvas, 30, 70, 80, 30, RED);
graphics_fill_rect(canvas, 115, 70, 80, 30, BLUE);
graphics_draw_string(canvas, 5, 10, temp, &bitstreamveraserif10, BLACK, FS_BOLD);
graphics_draw_string(canvas, 5, 25, instel, &bitstreamveraserif10, BLACK, FS_BOLD);
graphics_draw_string(canvas, 40, 77, "TEMP +", &bitstreamveraserif10, BLACK, FS_BOLD);
graphics_draw_string(canvas, 125, 77, "TEMP -", &bitstreamveraserif10, BLACK, FS_BOLD);
if (temp_val < temp_instel)
{
graphics_draw_string(canvas, 5, 40, "De gemeten temp ligt te laag", &bitstreamveraserif10, BLUE, FS_BOLD);
}
else
{
if (temp_val == temp_instel)
{
graphics_draw_string(canvas, 5, 40, "De gewenste temp is bereikt", &bitstreamveraserif10, BLACK, FS_BOLD);
}
else
{
graphics_draw_string(canvas, 5, 40, "De gemeten temp ligt te hoog", &bitstreamveraserif10, RED, FS_BOLD);
}
}
graphics_set_visible_canvas(graphics, canvas);
while (!graphics_visible_canvas_is_set(graphics));
}
void main(void)
{
init_disp_pwm();
while(1)
{
read_from_sensor();
set_temp();
print_temp();
}
}
Nu volgt het voorbeeld programma. Dit is echter een totaal ander programma, met andere toepassingen. Wel wordt hier gebruikt van het touchscreen en het klikken op bepaalde locaties. Hier volgt het voorbeeld programma:
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <graphics.h>
#include <touchscreen.h>
#include <pointer.h>
#include <drv_led.h>
#include "generic_devices.h"
#include "devices.h"
#include "led_info.h"
#define WIDTH 320
#define HEIGHT 240
char *cal1 = "Touch screen at marker";
graphics_t * display;
canvas_t * canvas;
touchscreen_t * tft_touch;
touchscreen_data_t * position;
touchscreen_callback_t callback;
pointer_t * ptr;
pointer_state_t * pointer_state;
led_t * leds;
extern __no_sdata graphics_bitmap_t _lc_ub_rgbcolors_bmp; // linker name for beginning of bitmap block
extern __no_sdata graphics_bitmap_t _lc_ue_rgbcolors_bmp;
graphics_bitmap_t * bmp = &_lc_ub_rgbcolors_bmp;
void update_leds (const uint32_t * col_buff);
void set_all_leds (uint32_t value);
static void draw_mark(int x, int y, int width, int height, void *vp);
void main (void)
{
// Connect to our drivers for the TFT, touch sensor.
tft_touch = touchscreen_open(TOUCHSCREEN_1);
ptr = pointer_open(POINTER_1);
display = graphics_open(GRAPHICS_1);
canvas = graphics_get_visible_canvas(display);
leds = led_open(DRV_LED_1);
led_turn_all_off(leds);
// Clear screen
graphics_fill_canvas(canvas, BLACK);
graphics_set_visible_canvas(display, canvas);
// Update display and turn off LEDs
while(!graphics_visible_canvas_is_set(display));
// Set up and calibrate touch screen.
touchscreen_set_callback(tft_touch, draw_mark, canvas);
while(!touchscreen_calibrate(tft_touch, 320, 240))
{
set_all_leds(0xFF0000); // If Touchscreen can't calibrate RED ALERT!
}
led_turn_all_off(leds);
// Put colormap on TFT
graphics_draw_bitmap(canvas, bmp, 0, 0, 320, 240, 0);
graphics_set_visible_canvas(display, canvas);
// Start picking colors!
while(1)
{
if (pointer_update(ptr, pointer_state))
{
set_all_leds(graphics_get_pixel(canvas, pointer_state->x, pointer_state->y));
}
}
}
void set_all_leds (uint32_t value)
{
for(int i = 0; i < LEDS_NUM_LED_IDS; )
{
led_set_intensity(leds, i++, (uint8_t)(value>>16)); // Red
led_set_intensity(leds, i++, (uint8_t)(value>>8)); // Green
led_set_intensity(leds, i++, (uint8_t)value); // Blue
}
}
static void draw_mark(int x, int y, int width, int height, void *vp)
{
graphics_draw_circle(canvas, x, y, 10, 0xff00ff);
graphics_draw_line(canvas, x - 15, y, x + 15, y, 0x00ffff);
graphics_draw_line(canvas, x, y - 15, x, y + 15, 0x00ffff);
graphics_draw_string(canvas, 50, 110, cal1, NULL, 0xffffff, 0);
graphics_set_visible_canvas(display, canvas);
}
[Bericht gewijzigd door Henry S. op (31%)]
Henry S.
Moderator
Confucius says chà bù duo. Deze post is niet door ChatGPT gegenereerd. De 2019 CO labvoeding.
Verder http://www.circuitsonline.net/forum/view/81921 en een waarschuwing wegens het opnieuw openen van een topic over de hetzelfde schoolopdracht, ook wegens een topickick en het neerplempen van code zonder zelf wat te proberen.
http://www.circuitsonline.net/forum/faq
http://www.circuitsonline.net/forum/view/29138
Goed lezen, krijg je 24 uur de tijd voor.