Projekte
workwind
NDS3 Distance Demo
main.c
Projekte
Forum
Doku
Öffentliche Projekte
Startseite
Beispielprogramme
Projekte von anderen
Welcome
Username
Passwort
Eingeloggt bleiben
Zugangsdaten vergessen?
Registrieren
Projektverwaltung
⇨ Please choose! ⇦
——————————————————
✎ Create new project...
★ Browse existing projects...
——————————————————
⚬ MotorTest#1
⚬ C Tutorial 8#1
⚬ NIBO2 C Project#1
⚙ C Tutorial 15#1
⚬ 2010_11_18_el_test001#1
NDS3 Distance Demo
main.c
Project details
Compiler settings
Nachrichten
Sie sind nicht eingeloggt.
Neuigkeiten
★
NiboRoboLib 3.6
2017-01-17: Neue Version 3.6
★
NiboRoboLib 3.4.1
2016-04-16: Neue Version 3.4.1
★
Coding Tutorial
2015-11-22: Jetzt auch für den NIBO burger!
Site-Statistic
7416 private projects
378 public projects
16172649 lines compiled
58122 builds
NIBO
@
nds3_distance_demo/main.c [read only]
/* BSD-License: Copyright (c) 2007 by Nils Springob, nicai-systems, Germany All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name nicai-systems nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "nibo/niboconfig.h" #include "nibo/iodefs.h" #include "nibo/delay.h" #include "nibo/display.h" #include "nibo/gfx.h" #include "nibo/leds.h" #include "nibo/pwm.h" #include "nibo/bot.h" #include "nibo/nds3.h" #include "nibo/copro.h" #include "nibo/spi.h" #include "nibo/i2cmaster.h" #include <avr/interrupt.h> #include <avr/pgmspace.h> #include <stdio.h> #include <stdlib.h> float volt_flt = 10.0; char txt[16]; // Richtung mit der groessten Reflexion ermitteln uint8_t find_minimum_distance() { uint16_t max_reflex = 0; uint8_t mindir = 2; for (uint8_t i=0; i<5; i++) { if (copro_distance[i]>max_reflex) { max_reflex = copro_distance[i]; mindir = i; } } return mindir; } int main(void) { sei(); // enable interrupts leds_init(); pwm_init(); bot_init(); i2c_init(); spi_init(); if (display_init()!=0) { leds_set_displaylight(50); if (display_type==2) { gfx_init(); } } gfx_fill(0x00); gfx_move(15, 0); gfx_set_proportional(1); gfx_print_text("nibo"); gfx_set_proportional(0); nds3_move(90); copro_ir_startMeasure(); while (1) { gfx_draw_mode(GFX_DM_JAM2); delay(100); // Spannung bot_update(); char text[20]; float volt = 0.0160 * bot_supply; sprintf(text, "%2.1fV ", (double)volt); gfx_set_proportional(0); gfx_move(45, 0); gfx_print_text(text); volt_flt = 0.9*volt_flt+0.1*volt; if (volt_flt<8.0) { gfx_fill(0x00); gfx_move(25, 20); gfx_set_proportional(1); gfx_print_text("Please recharge"); gfx_move(35, 30); gfx_print_text("batteries!"); gfx_set_proportional(0); while(1) { leds_set_headlights(0); clear_output_bit(IO_RESET_CO); leds_set_displaylight(500); IO_LEDS_RED_PORT = 0xaa; IO_LEDS_GREEN_PORT = 0; delay(500); leds_set_displaylight(0); IO_LEDS_RED_PORT = 0x55; IO_LEDS_GREEN_PORT = 0; delay(500); } } copro_update(); uint8_t dir = find_minimum_distance(); // Falls das NDS3 Modul nichts mehr zu tun hat: if (!nds3_get_busy ()) { // Letzte gemessene Distanz ermitteln und anzeigen: uint8_t dist = nds3_get_dist(); gfx_move(50, 24); sprintf(txt, "dist: %i cm ", dist); gfx_print_text(txt); // Richtung der IR-Reflexsensoren in NDS3 Richtung umrechnen und anzeigen: switch(dir) { case 4: dir=0; break; case 3: dir=45; break; case 2: dir=90; break; case 1: dir=135; break; case 0: dir=180; break; } gfx_move(50, 16); sprintf(txt, "dir: %i ", dir); gfx_print_text(txt); // NDS3 Modul in die entsprechende Richtung drehen: nds3_move(dir); } } }
Compiler results:
Werbung
Online
bradlytennant85
brandi20b03191419
Clarazkajurdy
coreybrowning490
jaimemenhennitt99
KennethsBew
marilynnhardee258
Marinagtq
ramonita59j0588088
SherinkaDek
sherrylfelder0511264